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 : 276800 : init_final (const char *filename ATTRIBUTE_UNUSED)
210 : : {
211 : 276800 : app_on = 0;
212 : 276800 : final_sequence = 0;
213 : :
214 : : #ifdef ASSEMBLER_DIALECT
215 : 276800 : dialect_number = ASSEMBLER_DIALECT;
216 : : #endif
217 : 276800 : }
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 : 1441151 : default_function_pro_epilogue (FILE *)
225 : : {
226 : 1441151 : }
227 : :
228 : : void
229 : 61869 : default_function_switched_text_sections (FILE *file ATTRIBUTE_UNUSED,
230 : : tree decl ATTRIBUTE_UNUSED,
231 : : bool new_is_cold ATTRIBUTE_UNUSED)
232 : : {
233 : 61869 : }
234 : :
235 : : /* Default target hook that outputs nothing to a stream. */
236 : : void
237 : 2991428 : no_asm_to_stream (FILE *file ATTRIBUTE_UNUSED)
238 : : {
239 : 2991428 : }
240 : :
241 : : /* Enable APP processing of subsequent output.
242 : : Used before the output from an `asm' statement. */
243 : :
244 : : void
245 : 47415 : app_enable (void)
246 : : {
247 : 47415 : if (! app_on)
248 : : {
249 : 44226 : fputs (ASM_APP_ON, asm_out_file);
250 : 44226 : app_on = 1;
251 : : }
252 : 47415 : }
253 : :
254 : : /* Disable APP processing of subsequent output.
255 : : Called from varasm.cc before most kinds of output. */
256 : :
257 : : void
258 : 143825493 : app_disable (void)
259 : : {
260 : 143825493 : if (app_on)
261 : : {
262 : 42963 : fputs (ASM_APP_OFF, asm_out_file);
263 : 42963 : app_on = 0;
264 : : }
265 : 143825493 : }
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 : 1441943 : init_insn_lengths (void)
319 : : {
320 : 1441943 : if (uid_shuid)
321 : : {
322 : 1437594 : free (uid_shuid);
323 : 1437594 : uid_shuid = 0;
324 : : }
325 : 1441943 : if (insn_lengths)
326 : : {
327 : 1437594 : free (insn_lengths);
328 : 1437594 : insn_lengths = 0;
329 : 1437594 : insn_lengths_max_uid = 0;
330 : : }
331 : 1441943 : if (HAVE_ATTR_length)
332 : 1441943 : INSN_ADDRESSES_FREE ();
333 : 1441943 : if (uid_align)
334 : : {
335 : 1437594 : free (uid_align);
336 : 1437594 : uid_align = 0;
337 : : }
338 : 1441943 : }
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 : 352389533 : get_attr_length_1 (rtx_insn *insn, int (*fallback_fn) (rtx_insn *))
345 : : {
346 : 352389533 : rtx body;
347 : 352389533 : int i;
348 : 352389533 : int length = 0;
349 : :
350 : 352389533 : if (!HAVE_ATTR_length)
351 : : return 0;
352 : :
353 : 352389533 : if (insn_lengths_max_uid > INSN_UID (insn))
354 : 3503 : return insn_lengths[INSN_UID (insn)];
355 : : else
356 : 352386030 : switch (GET_CODE (insn))
357 : : {
358 : : case NOTE:
359 : : case BARRIER:
360 : : case CODE_LABEL:
361 : : case DEBUG_INSN:
362 : : return 0;
363 : :
364 : 9044952 : case CALL_INSN:
365 : 9044952 : case JUMP_INSN:
366 : 9044952 : body = PATTERN (insn);
367 : 9044952 : if (GET_CODE (body) == ASM_INPUT || asm_noperands (body) >= 0)
368 : 85 : length = asm_insn_count (body) * fallback_fn (insn);
369 : : else
370 : 9044867 : length = fallback_fn (insn);
371 : : break;
372 : :
373 : 333991031 : case INSN:
374 : 333991031 : body = PATTERN (insn);
375 : 333991031 : if (GET_CODE (body) == USE || GET_CODE (body) == CLOBBER)
376 : : return 0;
377 : :
378 : 333659364 : else if (GET_CODE (body) == ASM_INPUT || asm_noperands (body) >= 0)
379 : 7545 : length = asm_insn_count (body) * fallback_fn (insn);
380 : 333651819 : 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 : 333651819 : 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 : 335861438 : get_attr_length (rtx_insn *insn)
401 : : {
402 : 335861438 : 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 : 16528095 : get_attr_min_length (rtx_insn *insn)
409 : : {
410 : 16528095 : 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 : 6572 : final_addr_vec_align (rtx_jump_table_data *addr_vec)
473 : : {
474 : 6572 : int align = GET_MODE_SIZE (addr_vec->get_data_mode ());
475 : :
476 : 13055 : if (align > BIGGEST_ALIGNMENT / BITS_PER_UNIT)
477 : 0 : align = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
478 : 6572 : 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 : 952 : label_to_alignment (rtx label)
500 : : {
501 : 952 : if (CODE_LABEL_NUMBER (label) <= max_labelno)
502 : 952 : 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 : 26309435 : align_fuzz (rtx start, rtx end, int known_align_log, unsigned int growth)
536 : : {
537 : 26309435 : int uid = INSN_UID (start);
538 : 26309435 : rtx align_label;
539 : 26309435 : int known_align = 1 << known_align_log;
540 : 26309435 : int end_shuid = INSN_SHUID (end);
541 : 26309435 : int fuzz = 0;
542 : :
543 : 38594872 : for (align_label = uid_align[uid]; align_label; align_label = uid_align[uid])
544 : : {
545 : 14811007 : int align_addr, new_align;
546 : :
547 : 14811007 : uid = INSN_UID (align_label);
548 : 14811007 : align_addr = INSN_ADDRESSES (uid) - insn_lengths[uid];
549 : 14811007 : if (uid_shuid[uid] > end_shuid)
550 : : break;
551 : 12285437 : align_flags alignment = LABEL_TO_ALIGNMENT (align_label);
552 : 12285437 : new_align = 1 << alignment.levels[0].log;
553 : 12285437 : if (new_align < known_align)
554 : 0 : continue;
555 : 12285437 : fuzz += (-align_addr ^ growth) & (new_align - known_align);
556 : 12285437 : known_align = new_align;
557 : : }
558 : 26309435 : 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 : 26309435 : insn_current_reference_address (rtx_insn *branch)
575 : : {
576 : 26309435 : rtx dest;
577 : 26309435 : int seq_uid;
578 : :
579 : 26309435 : if (! INSN_ADDRESSES_SET_P ())
580 : : return 0;
581 : :
582 : 26309435 : rtx_insn *seq = NEXT_INSN (PREV_INSN (branch));
583 : 26309435 : seq_uid = INSN_UID (seq);
584 : 26309435 : 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 : 26309435 : dest = JUMP_LABEL (branch);
592 : :
593 : : /* BRANCH has no proper alignment chain set, so use SEQ.
594 : : BRANCH also has no INSN_SHUID. */
595 : 26309435 : if (INSN_SHUID (seq) < INSN_SHUID (dest))
596 : : {
597 : : /* Forward branch. */
598 : 19034850 : return (insn_last_address + insn_lengths[seq_uid]
599 : 19034850 : - align_fuzz (seq, dest, length_unit_log, ~0));
600 : : }
601 : : else
602 : : {
603 : : /* Backward branch. */
604 : 7274585 : return (insn_current_address
605 : 7274585 : + align_fuzz (dest, seq, length_unit_log, ~0));
606 : : }
607 : : }
608 : :
609 : : /* Compute branch alignments based on CFG profile. */
610 : :
611 : : void
612 : 1435842 : compute_alignments (void)
613 : : {
614 : 1435842 : basic_block bb;
615 : 1435842 : align_flags max_alignment;
616 : :
617 : 1435842 : label_align.truncate (0);
618 : :
619 : 1435842 : max_labelno = max_label_num ();
620 : 1435842 : min_labelno = get_first_label_num ();
621 : 1435842 : 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 : 1435842 : if (! optimize || optimize_function_for_size_p (cfun))
625 : 488946 : return;
626 : :
627 : 946896 : 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 : 946896 : loop_optimizer_init (AVOID_CFG_MODIFICATIONS);
634 : 946896 : profile_count count_threshold = cfun->cfg->count_max / param_align_threshold;
635 : :
636 : 946896 : 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 : 10842904 : FOR_EACH_BB_FN (bb, cfun)
643 : : {
644 : 9896008 : rtx_insn *label = BB_HEAD (bb);
645 : 9896008 : bool has_fallthru = 0;
646 : 9896008 : edge e;
647 : 9896008 : edge_iterator ei;
648 : :
649 : 16344386 : if (!LABEL_P (label)
650 : 9896008 : || optimize_bb_for_size_p (bb))
651 : : {
652 : 6448378 : 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 : 6449842 : continue;
659 : : }
660 : 3447630 : max_alignment = LABEL_ALIGN (label);
661 : 3447630 : profile_count fallthru_count = profile_count::zero ();
662 : 3447630 : profile_count branch_count = profile_count::zero ();
663 : :
664 : 10089215 : FOR_EACH_EDGE (e, ei, bb->preds)
665 : : {
666 : 6641585 : if (e->flags & EDGE_FALLTHRU)
667 : 2161920 : has_fallthru = 1, fallthru_count += e->count ();
668 : : else
669 : 4479665 : branch_count += e->count ();
670 : : }
671 : 3447630 : if (dump_file)
672 : : {
673 : 117 : fprintf (dump_file, "BB %4i loop %2i loop_depth"
674 : : " %2i fall ",
675 : 117 : bb->index, bb->loop_father->num,
676 : : bb_loop_depth (bb));
677 : 117 : fallthru_count.dump (dump_file);
678 : 117 : fprintf (dump_file, " branch ");
679 : 117 : branch_count.dump (dump_file);
680 : 117 : if (!bb->loop_father->inner && bb->loop_father->num)
681 : 20 : fprintf (dump_file, " inner_loop");
682 : 117 : if (bb->loop_father->header == bb)
683 : 18 : fprintf (dump_file, " loop_header");
684 : 117 : fprintf (dump_file, "\n");
685 : : }
686 : 3447630 : if (!fallthru_count.initialized_p () || !branch_count.initialized_p ())
687 : 1464 : 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 : 3446166 : if (!has_fallthru
700 : 3446166 : && (branch_count > count_threshold
701 : 330241 : || (bb->count > bb->prev_bb->count * 10
702 : 24969 : && (bb->prev_bb->count
703 : 2491574 : <= ENTRY_BLOCK_PTR_FOR_FN (cfun)->count / 2))))
704 : : {
705 : 979561 : align_flags alignment = JUMP_ALIGN (label);
706 : 979561 : if (dump_file)
707 : 40 : fprintf (dump_file, " jump alignment added.\n");
708 : 979561 : 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 : 3446166 : if (has_fallthru
713 : 2160896 : && !(single_succ_p (bb)
714 : 732435 : && single_succ (bb) == EXIT_BLOCK_PTR_FOR_FN (cfun))
715 : 1831277 : && optimize_bb_for_speed_p (bb)
716 : 1831277 : && branch_count + fallthru_count > count_threshold
717 : 5607062 : && (branch_count > fallthru_count * param_align_loop_iterations))
718 : : {
719 : 281229 : align_flags alignment = LOOP_ALIGN (label);
720 : 281229 : if (dump_file)
721 : 9 : fprintf (dump_file, " internal loop alignment added.\n");
722 : 281229 : max_alignment = align_flags::max (max_alignment, alignment);
723 : : }
724 : 3446166 : LABEL_TO_ALIGNMENT (label) = max_alignment;
725 : : }
726 : :
727 : 946896 : loop_optimizer_finalize ();
728 : 946896 : 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 : 283157 : pass_compute_alignments (gcc::context *ctxt)
791 : 566314 : : rtl_opt_pass (pass_data_compute_alignments, ctxt)
792 : : {}
793 : :
794 : : /* opt_pass methods: */
795 : 1435842 : unsigned int execute (function *) final override
796 : : {
797 : 1435842 : compute_alignments ();
798 : 1435842 : return 0;
799 : : }
800 : :
801 : : }; // class pass_compute_alignments
802 : :
803 : : } // anon namespace
804 : :
805 : : rtl_opt_pass *
806 : 283157 : make_pass_compute_alignments (gcc::context *ctxt)
807 : : {
808 : 283157 : 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 : 1437594 : shorten_branches (rtx_insn *first)
825 : : {
826 : 1437594 : rtx_insn *insn;
827 : 1437594 : int max_uid;
828 : 1437594 : int i;
829 : 1437594 : rtx_insn *seq;
830 : 1437594 : bool something_changed = true;
831 : 1437594 : char *varying_length;
832 : 1437594 : rtx body;
833 : 1437594 : int uid;
834 : 1437594 : rtx align_tab[MAX_CODE_ALIGN + 1];
835 : :
836 : : /* Compute maximum UID and allocate label_align / uid_shuid. */
837 : 1437594 : max_uid = get_max_uid ();
838 : :
839 : : /* Free uid_shuid before reallocating it. */
840 : 1437594 : free (uid_shuid);
841 : :
842 : 1437594 : uid_shuid = XNEWVEC (int, max_uid);
843 : :
844 : 1437594 : 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 : 1437594 : align_flags max_alignment;
854 : :
855 : 190064692 : for (insn = get_insns (), i = 1; insn; insn = NEXT_INSN (insn))
856 : : {
857 : 188627098 : INSN_SHUID (insn) = i++;
858 : 188627098 : if (INSN_P (insn))
859 : 89930181 : continue;
860 : :
861 : 98696917 : if (rtx_code_label *label = dyn_cast <rtx_code_label *> (insn))
862 : : {
863 : : /* Merge in alignments computed by compute_alignments. */
864 : 6492011 : align_flags alignment = LABEL_TO_ALIGNMENT (label);
865 : 6492011 : max_alignment = align_flags::max (max_alignment, alignment);
866 : :
867 : 6492011 : rtx_jump_table_data *table = jump_table_for_label (label);
868 : 6492011 : if (!table)
869 : : {
870 : 6485439 : align_flags alignment = LABEL_ALIGN (label);
871 : 6485439 : 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 : 6492011 : if ((JUMP_TABLES_IN_TEXT_SECTION
876 : 6492011 : || 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 : 6492011 : LABEL_TO_ALIGNMENT (label) = max_alignment;
883 : 6492011 : max_alignment = align_flags ();
884 : : }
885 : 92204906 : else if (BARRIER_P (insn))
886 : : {
887 : : rtx_insn *label;
888 : :
889 : 24160019 : for (label = insn; label && ! INSN_P (label);
890 : 19652408 : label = NEXT_INSN (label))
891 : 22677807 : if (LABEL_P (label))
892 : : {
893 : 3025399 : align_flags alignment
894 : 3025399 : = align_flags (LABEL_ALIGN_AFTER_BARRIER (insn));
895 : 3025399 : max_alignment = align_flags::max (max_alignment, alignment);
896 : 3025399 : break;
897 : : }
898 : : }
899 : : }
900 : 1437594 : if (!HAVE_ATTR_length)
901 : : return;
902 : :
903 : : /* Allocate the rest of the arrays. */
904 : 1437594 : insn_lengths = XNEWVEC (int, max_uid);
905 : 1437594 : 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 : 1437594 : INSN_ADDRESSES_ALLOC (max_uid);
909 : :
910 : 1437594 : 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 : 1437594 : uid_align = XCNEWVEC (rtx, max_uid);
918 : :
919 : 25876692 : for (i = MAX_CODE_ALIGN + 1; --i >= 0;)
920 : 24439098 : align_tab[i] = NULL_RTX;
921 : 1437594 : seq = get_last_insn ();
922 : 190064692 : for (; seq; seq = PREV_INSN (seq))
923 : : {
924 : 188627098 : int uid = INSN_UID (seq);
925 : 188627098 : int log;
926 : 188627098 : log = (LABEL_P (seq) ? LABEL_TO_ALIGNMENT (seq).levels[0].log : 0);
927 : 188627098 : uid_align[uid] = align_tab[0];
928 : 188627098 : if (log)
929 : : {
930 : : /* Found an alignment label. */
931 : 1208899 : gcc_checking_assert (log < MAX_CODE_ALIGN + 1);
932 : 1208899 : uid_align[uid] = align_tab[log];
933 : 6044582 : for (i = log - 1; i >= 0; i--)
934 : 4835683 : 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 : 1437594 : 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 : 1437594 : int (*length_fun) (rtx_insn *) = increasing ? insn_min_length : insn_default_length;
1008 : :
1009 : 1437594 : for (insn_current_address = 0, insn = first;
1010 : 190064692 : insn != 0;
1011 : 188627098 : insn_current_address += insn_lengths[uid], insn = NEXT_INSN (insn))
1012 : : {
1013 : 188627098 : uid = INSN_UID (insn);
1014 : :
1015 : 188627098 : insn_lengths[uid] = 0;
1016 : :
1017 : 188627098 : if (LABEL_P (insn))
1018 : : {
1019 : 6492011 : int log = LABEL_TO_ALIGNMENT (insn).levels[0].log;
1020 : 6492011 : if (log)
1021 : : {
1022 : 1208899 : int align = 1 << log;
1023 : 1208899 : int new_address = (insn_current_address + align - 1) & -align;
1024 : 1208899 : insn_lengths[uid] = new_address - insn_current_address;
1025 : : }
1026 : : }
1027 : :
1028 : 188627098 : INSN_ADDRESSES (uid) = insn_current_address + insn_lengths[uid];
1029 : :
1030 : 188627098 : if (NOTE_P (insn) || BARRIER_P (insn)
1031 : 96428764 : || LABEL_P (insn) || DEBUG_INSN_P (insn))
1032 : 98690349 : continue;
1033 : 89936749 : if (insn->deleted ())
1034 : 0 : continue;
1035 : :
1036 : 89936749 : body = PATTERN (insn);
1037 : 89936749 : 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 : 6572 : if (JUMP_TABLES_IN_TEXT_SECTION
1042 : 6572 : || 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 : 89930177 : else if (GET_CODE (body) == ASM_INPUT || asm_noperands (body) >= 0)
1049 : 106304 : insn_lengths[uid] = asm_insn_count (body) * insn_default_length (insn);
1050 : 89823873 : 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 : 89823873 : else if (GET_CODE (body) != USE && GET_CODE (body) != CLOBBER)
1092 : : {
1093 : 88788896 : insn_lengths[uid] = length_fun (insn);
1094 : 88788896 : 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 : 2691790 : while (something_changed)
1110 : : {
1111 : 1683101 : something_changed = false;
1112 : 1683101 : insn_current_align = MAX_CODE_ALIGN - 1;
1113 : 339403221 : for (insn_current_address = 0, insn = first;
1114 : 339403221 : insn != 0;
1115 : 337720120 : insn = NEXT_INSN (insn))
1116 : : {
1117 : 337720120 : int new_length;
1118 : : #ifdef ADJUST_INSN_LENGTH
1119 : : int tmp_length;
1120 : : #endif
1121 : 337720120 : int length_align;
1122 : :
1123 : 337720120 : uid = INSN_UID (insn);
1124 : :
1125 : 337720120 : if (rtx_code_label *label = dyn_cast <rtx_code_label *> (insn))
1126 : : {
1127 : 11490284 : 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 : 11490284 : if (log > insn_current_align)
1151 : : {
1152 : 2433558 : int align = 1 << log;
1153 : 2433558 : int new_address= (insn_current_address + align - 1) & -align;
1154 : 2433558 : insn_lengths[uid] = new_address - insn_current_address;
1155 : 2433558 : insn_current_align = log;
1156 : 2433558 : insn_current_address = new_address;
1157 : : }
1158 : : else
1159 : 9056726 : insn_lengths[uid] = 0;
1160 : 11490284 : INSN_ADDRESSES (uid) = insn_current_address;
1161 : 11490284 : continue;
1162 : 11490284 : }
1163 : :
1164 : 326229836 : length_align = INSN_LENGTH_ALIGNMENT (insn);
1165 : 326229836 : if (length_align < insn_current_align)
1166 : 4116659 : insn_current_align = length_align;
1167 : :
1168 : 326229836 : insn_last_address = INSN_ADDRESSES (uid);
1169 : 326229836 : 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 : 326229836 : if (! (varying_length[uid]))
1290 : : {
1291 : 311369528 : if (NONJUMP_INSN_P (insn)
1292 : 311369528 : && 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 : 311369528 : insn_current_address += insn_lengths[uid];
1309 : :
1310 : 311369528 : continue;
1311 : 311369528 : }
1312 : :
1313 : 14860308 : 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 : 14860308 : new_length = insn_current_length (insn);
1352 : 14860308 : 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 : 14860308 : if (new_length != insn_lengths[uid]
1363 : 5001415 : && (!increasing || new_length > insn_lengths[uid]))
1364 : : {
1365 : 5001415 : insn_lengths[uid] = new_length;
1366 : 5001415 : something_changed = true;
1367 : : }
1368 : : else
1369 : 9858893 : insn_current_address += insn_lengths[uid] - new_length;
1370 : : }
1371 : : /* For a non-optimizing compile, do only a single pass. */
1372 : 1683101 : if (!increasing)
1373 : : break;
1374 : : }
1375 : 1437594 : crtl->max_insn_address = insn_current_address;
1376 : 1437594 : 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 : 113934 : asm_insn_count (rtx body)
1385 : : {
1386 : 113934 : const char *templ;
1387 : :
1388 : 113934 : if (GET_CODE (body) == ASM_INPUT)
1389 : 3545 : templ = XSTR (body, 0);
1390 : : else
1391 : 110389 : templ = decode_asm_operands (body, NULL, NULL, NULL, NULL, NULL);
1392 : :
1393 : 113934 : 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 : 838530 : asm_str_count (const char *templ)
1400 : : {
1401 : 838530 : int count = 1;
1402 : :
1403 : 838530 : if (!*templ)
1404 : : return 0;
1405 : :
1406 : 5341155 : for (; *templ; templ++)
1407 : 5038404 : if (IS_ASM_LOGICAL_LINE_SEPARATOR (*templ, templ)
1408 : 5030943 : || *templ == '\n')
1409 : 229285 : count++;
1410 : :
1411 : : return count;
1412 : : }
1413 : :
1414 : : /* Return true if DWARF2 debug info can be emitted for DECL. */
1415 : :
1416 : : static bool
1417 : 2944169 : dwarf2_debug_info_emitted_p (tree decl)
1418 : : {
1419 : : /* When DWARF2 debug info is not generated internally. */
1420 : 2944169 : if (!dwarf_debuginfo_p () && !dwarf_based_debuginfo_p ())
1421 : : return false;
1422 : :
1423 : 1133511 : 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 : 15731843 : change_scope (rtx_insn *orig_insn, tree s1, tree s2)
1446 : : {
1447 : 15731843 : rtx_insn *insn = orig_insn;
1448 : 15731843 : tree com = NULL_TREE;
1449 : 15731843 : tree ts1 = s1, ts2 = s2;
1450 : 15731843 : tree s;
1451 : :
1452 : 50597810 : while (ts1 != ts2)
1453 : : {
1454 : 34865967 : gcc_assert (ts1 && ts2);
1455 : 34865967 : if (BLOCK_NUMBER (ts1) > BLOCK_NUMBER (ts2))
1456 : 14213356 : ts1 = BLOCK_SUPERCONTEXT (ts1);
1457 : 20652611 : else if (BLOCK_NUMBER (ts1) < BLOCK_NUMBER (ts2))
1458 : 14213356 : ts2 = BLOCK_SUPERCONTEXT (ts2);
1459 : : else
1460 : : {
1461 : 6439255 : ts1 = BLOCK_SUPERCONTEXT (ts1);
1462 : 6439255 : ts2 = BLOCK_SUPERCONTEXT (ts2);
1463 : : }
1464 : : }
1465 : 36384454 : com = ts1;
1466 : :
1467 : : /* Close scopes. */
1468 : : s = s1;
1469 : 36384454 : while (s != com)
1470 : : {
1471 : 20652611 : rtx_note *note = emit_note_before (NOTE_INSN_BLOCK_END, insn);
1472 : 20652611 : NOTE_BLOCK (note) = s;
1473 : 20652611 : s = BLOCK_SUPERCONTEXT (s);
1474 : : }
1475 : :
1476 : : /* Open scopes. */
1477 : : s = s2;
1478 : 36384454 : while (s != com)
1479 : : {
1480 : 20652611 : insn = emit_note_before (NOTE_INSN_BLOCK_BEG, insn);
1481 : 20652611 : NOTE_BLOCK (insn) = s;
1482 : 20652611 : s = BLOCK_SUPERCONTEXT (s);
1483 : : }
1484 : 15731843 : }
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 : 556569 : reemit_insn_block_notes (void)
1491 : : {
1492 : 556569 : tree cur_block = DECL_INITIAL (cfun->decl);
1493 : 556569 : rtx_insn *insn;
1494 : :
1495 : 556569 : insn = get_insns ();
1496 : 132742321 : for (; insn; insn = NEXT_INSN (insn))
1497 : : {
1498 : 132185752 : tree this_block;
1499 : :
1500 : : /* Prevent lexical blocks from straddling section boundaries. */
1501 : 132185752 : if (NOTE_P (insn))
1502 : 81950516 : switch (NOTE_KIND (insn))
1503 : : {
1504 : : case NOTE_INSN_SWITCH_TEXT_SECTIONS:
1505 : : {
1506 : 78194 : for (tree s = cur_block; s != DECL_INITIAL (cfun->decl);
1507 : 57821 : s = BLOCK_SUPERCONTEXT (s))
1508 : : {
1509 : 57821 : rtx_note *note = emit_note_before (NOTE_INSN_BLOCK_END, insn);
1510 : 57821 : NOTE_BLOCK (note) = s;
1511 : 57821 : note = emit_note_after (NOTE_INSN_BLOCK_BEG, insn);
1512 : 57821 : NOTE_BLOCK (note) = s;
1513 : : }
1514 : : }
1515 : : break;
1516 : :
1517 : 9989650 : case NOTE_INSN_BEGIN_STMT:
1518 : 9989650 : case NOTE_INSN_INLINE_ENTRY:
1519 : 9989650 : this_block = LOCATION_BLOCK (NOTE_MARKER_LOCATION (insn));
1520 : 9980240 : if (!this_block)
1521 : 13179 : continue;
1522 : 9976471 : goto set_cur_block_to_this_block;
1523 : :
1524 : 71940493 : default:
1525 : 71940493 : continue;
1526 : 71940493 : }
1527 : :
1528 : 50255609 : if (!active_insn_p (insn))
1529 : 6789754 : continue;
1530 : :
1531 : : /* Avoid putting scope notes between jump table and its label. */
1532 : 43465855 : if (JUMP_TABLE_DATA_P (insn))
1533 : 5701 : continue;
1534 : :
1535 : 43460154 : this_block = insn_scope (insn);
1536 : : /* For sequences compute scope resulting from merging all scopes
1537 : : of instructions nested inside. */
1538 : 43460154 : 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 : 43460154 : if (! this_block)
1548 : : {
1549 : 9676213 : if (INSN_LOCATION (insn) == UNKNOWN_LOCATION)
1550 : 4311765 : continue;
1551 : : else
1552 : 5364448 : this_block = DECL_INITIAL (cfun->decl);
1553 : : }
1554 : :
1555 : 33783941 : set_cur_block_to_this_block:
1556 : 49124860 : if (this_block != cur_block)
1557 : : {
1558 : 15175274 : change_scope (insn, cur_block, this_block);
1559 : 15175274 : cur_block = this_block;
1560 : : }
1561 : : }
1562 : :
1563 : : /* change_scope emits before the insn, not after. */
1564 : 556569 : rtx_note *note = emit_note (NOTE_INSN_DELETED);
1565 : 556569 : change_scope (note, cur_block, DECL_INITIAL (cfun->decl));
1566 : 556569 : delete_insn (note);
1567 : :
1568 : 556569 : reorder_blocks ();
1569 : 556569 : }
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 : 269 : get_some_local_dynamic_name ()
1579 : : {
1580 : 269 : subrtx_iterator::array_type array;
1581 : 269 : rtx_insn *insn;
1582 : :
1583 : 269 : if (some_local_dynamic_name)
1584 : : return some_local_dynamic_name;
1585 : :
1586 : 9526 : for (insn = get_insns (); insn ; insn = NEXT_INSN (insn))
1587 : 9525 : if (NONDEBUG_INSN_P (insn))
1588 : 18617 : FOR_EACH_SUBRTX (iter, array, PATTERN (insn), ALL)
1589 : : {
1590 : 16243 : const_rtx x = *iter;
1591 : 16243 : if (GET_CODE (x) == SYMBOL_REF)
1592 : : {
1593 : 601 : if (SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_DYNAMIC)
1594 : 228 : return some_local_dynamic_name = XSTR (x, 0);
1595 : 373 : if (CONSTANT_POOL_ADDRESS_P (x))
1596 : 0 : iter.substitute (get_pool_constant (x));
1597 : : }
1598 : : }
1599 : :
1600 : : return 0;
1601 : 269 : }
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 : 50459192 : set_next_view_needed (int *seen)
1612 : : {
1613 : 50459192 : if (debug_variable_location_views)
1614 : 50459192 : *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 : 43653402 : clear_next_view_needed (int *seen)
1622 : : {
1623 : 43653402 : *seen &= ~SEEN_NEXT_VIEW;
1624 : 35671769 : }
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 : 85422994 : maybe_output_next_view (int *seen)
1631 : : {
1632 : 85422994 : if ((*seen & SEEN_NEXT_VIEW) != 0)
1633 : : {
1634 : 7981633 : clear_next_view_needed (seen);
1635 : 7981633 : (*debug_hooks->source_line) (last_linenum, last_columnnum,
1636 : : last_filename, last_discriminator,
1637 : : false);
1638 : : }
1639 : 85422994 : }
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 : 2838655 : in_initial_view_p (rtx_insn *insn)
1656 : : {
1657 : 2838655 : return (!DECL_IGNORED_P (current_function_decl)
1658 : 2811822 : && debug_variable_location_views
1659 : 1869917 : && insn && GET_CODE (insn) == NOTE
1660 : 4557892 : && (NOTE_KIND (insn) == NOTE_INSN_VAR_LOCATION
1661 : 797626 : || 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 : 1441151 : final_start_function_1 (rtx_insn **firstp, FILE *file, int *seen,
1679 : : int optimize_p ATTRIBUTE_UNUSED)
1680 : : {
1681 : 1441151 : block_depth = 0;
1682 : :
1683 : 1441151 : this_is_asm_operands = 0;
1684 : :
1685 : 1441151 : need_profile_function = false;
1686 : :
1687 : 1441151 : last_filename = LOCATION_FILE (prologue_location);
1688 : 1441151 : last_linenum = LOCATION_LINE (prologue_location);
1689 : 1441151 : last_columnnum = LOCATION_COLUMN (prologue_location);
1690 : 1441151 : last_discriminator = 0;
1691 : 1441151 : force_source_line = false;
1692 : :
1693 : 1441151 : high_block_linenum = high_function_linenum = last_linenum;
1694 : :
1695 : 1441151 : rtx_insn *first = *firstp;
1696 : 1441151 : if (in_initial_view_p (first))
1697 : : {
1698 : 1395752 : do
1699 : : {
1700 : 1395752 : final_scan_insn (first, file, 0, 0, seen);
1701 : 1395752 : first = NEXT_INSN (first);
1702 : : }
1703 : 1395752 : while (in_initial_view_p (first));
1704 : 474141 : *firstp = first;
1705 : : }
1706 : :
1707 : 1441151 : if (!DECL_IGNORED_P (current_function_decl))
1708 : 1414318 : debug_hooks->begin_prologue (last_linenum, last_columnnum,
1709 : : last_filename);
1710 : :
1711 : 1441151 : if (!dwarf2_debug_info_emitted_p (current_function_decl))
1712 : 897041 : dwarf2out_begin_prologue (0, 0, NULL);
1713 : :
1714 : 1441151 : if (DECL_IGNORED_P (current_function_decl) && last_linenum && last_filename)
1715 : 20835 : 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 : 1441151 : 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 : 1441151 : if (write_symbols)
1760 : : {
1761 : 556569 : reemit_insn_block_notes ();
1762 : 556569 : 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 : 556569 : TREE_ASM_WRITTEN (DECL_INITIAL (current_function_decl)) = 1;
1767 : : }
1768 : :
1769 : 1441151 : unsigned HOST_WIDE_INT min_frame_size
1770 : 1441151 : = constant_lower_bound (get_frame_size ());
1771 : 1441151 : 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 : 1441151 : 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 : 1441151 : if (! targetm.have_prologue ())
1785 : 0 : profile_after_prologue (file);
1786 : 1441151 : }
1787 : :
1788 : : /* This is an exported final_start_function_1, callable without SEEN. */
1789 : :
1790 : : void
1791 : 5308 : final_start_function (rtx_insn *first, FILE *file,
1792 : : int optimize_p ATTRIBUTE_UNUSED)
1793 : : {
1794 : 5308 : int seen = 0;
1795 : 5308 : final_start_function_1 (&first, file, &seen, optimize_p);
1796 : 5308 : gcc_assert (seen == 0);
1797 : 5308 : }
1798 : :
1799 : : static void
1800 : 1437595 : profile_after_prologue (FILE *file ATTRIBUTE_UNUSED)
1801 : : {
1802 : 1437595 : if (!targetm.profile_before_prologue () && crtl->profile)
1803 : 321 : profile_function (file);
1804 : 1437595 : }
1805 : :
1806 : : static void
1807 : 345 : 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 : 345 : rtx sval = NULL, chain = NULL;
1814 : :
1815 : 345 : if (cfun->returns_struct)
1816 : 0 : sval = targetm.calls.struct_value_rtx (TREE_TYPE (current_function_decl),
1817 : : true);
1818 : 345 : if (cfun->static_chain_decl)
1819 : 1 : chain = targetm.calls.static_chain (current_function_decl, true);
1820 : : #endif /* ASM_OUTPUT_REG_PUSH */
1821 : :
1822 : 345 : 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 : 345 : switch_to_section (current_function_section ());
1832 : :
1833 : : #ifdef ASM_OUTPUT_REG_PUSH
1834 : 345 : if (sval && REG_P (sval))
1835 : 0 : ASM_OUTPUT_REG_PUSH (file, REGNO (sval));
1836 : 345 : if (chain && REG_P (chain))
1837 : 1 : ASM_OUTPUT_REG_PUSH (file, REGNO (chain));
1838 : : #endif
1839 : :
1840 : 345 : FUNCTION_PROFILER (file, current_function_funcdef_no);
1841 : :
1842 : : #ifdef ASM_OUTPUT_REG_PUSH
1843 : 345 : if (chain && REG_P (chain))
1844 : 1 : ASM_OUTPUT_REG_POP (file, REGNO (chain));
1845 : 345 : if (sval && REG_P (sval))
1846 : 0 : ASM_OUTPUT_REG_POP (file, REGNO (sval));
1847 : : #endif
1848 : 345 : }
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 : 1441151 : final_end_function (void)
1856 : : {
1857 : 1441151 : app_disable ();
1858 : :
1859 : 1441151 : if (!DECL_IGNORED_P (current_function_decl))
1860 : 1414318 : 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 : 1441151 : targetm.asm_out.function_epilogue (asm_out_file);
1865 : :
1866 : : /* And debug output. */
1867 : 1441151 : if (!DECL_IGNORED_P (current_function_decl))
1868 : 1414318 : debug_hooks->end_epilogue (last_linenum, last_filename);
1869 : :
1870 : 1441151 : if (!dwarf2_debug_info_emitted_p (current_function_decl)
1871 : 1441151 : && dwarf2out_do_frame ())
1872 : 896966 : dwarf2out_end_epilogue (last_linenum, last_filename);
1873 : :
1874 : 1441151 : some_local_dynamic_name = 0;
1875 : 1441151 : }
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 : 240347779 : 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 : 240347779 : basic_block bb;
1886 : :
1887 : 240347779 : if (!flag_debug_asm)
1888 : : return;
1889 : :
1890 : 33869 : if (INSN_UID (insn) < bb_map_size
1891 : 33869 : && (bb = start_to_bb[INSN_UID (insn)]) != NULL)
1892 : : {
1893 : 2075 : edge e;
1894 : 2075 : edge_iterator ei;
1895 : :
1896 : 2075 : fprintf (file, "%s BLOCK %d", ASM_COMMENT_START, bb->index);
1897 : 2075 : if (bb->count.initialized_p ())
1898 : : {
1899 : 156 : fprintf (file, ", count:");
1900 : 156 : bb->count.dump (file);
1901 : : }
1902 : 2075 : fprintf (file, " seq:%d", (*bb_seqn)++);
1903 : 2075 : fprintf (file, "\n%s PRED:", ASM_COMMENT_START);
1904 : 4434 : FOR_EACH_EDGE (e, ei, bb->preds)
1905 : : {
1906 : 2359 : dump_edge_info (file, e, TDF_DETAILS, 0);
1907 : : }
1908 : 2075 : fprintf (file, "\n");
1909 : : }
1910 : 33869 : if (INSN_UID (insn) < bb_map_size
1911 : 33869 : && (bb = end_to_bb[INSN_UID (insn)]) != NULL)
1912 : : {
1913 : 2075 : edge e;
1914 : 2075 : edge_iterator ei;
1915 : :
1916 : 2075 : fprintf (asm_out_file, "%s SUCC:", ASM_COMMENT_START);
1917 : 4432 : FOR_EACH_EDGE (e, ei, bb->succs)
1918 : : {
1919 : 2357 : dump_edge_info (asm_out_file, e, TDF_DETAILS, 1);
1920 : : }
1921 : 2075 : 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 : 1437595 : final_1 (rtx_insn *first, FILE *file, int seen, int optimize_p)
1930 : : {
1931 : 1437595 : rtx_insn *insn, *next;
1932 : :
1933 : : /* Used for -dA dump. */
1934 : 1437595 : basic_block *start_to_bb = NULL;
1935 : 1437595 : basic_block *end_to_bb = NULL;
1936 : 1437595 : int bb_map_size = 0;
1937 : 1437595 : int bb_seqn = 0;
1938 : :
1939 : 1437595 : last_ignored_compare = 0;
1940 : :
1941 : 1437595 : init_recog ();
1942 : :
1943 : 1437595 : CC_STATUS_INIT;
1944 : :
1945 : 1437595 : 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 : 3266 : FOR_EACH_BB_REVERSE_FN (bb, cfun)
1956 : : {
1957 : 2075 : start_to_bb[INSN_UID (BB_HEAD (bb))] = bb;
1958 : 2075 : end_to_bb[INSN_UID (BB_END (bb))] = bb;
1959 : : }
1960 : : }
1961 : :
1962 : : /* Output the insns. */
1963 : 241785374 : for (insn = first; insn;)
1964 : : {
1965 : 240347779 : if (HAVE_ATTR_length)
1966 : : {
1967 : 240347779 : 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 : 53116406 : gcc_assert (NOTE_P (insn));
1972 : 53116406 : insn_current_address = -1;
1973 : : }
1974 : : else
1975 : 187231373 : 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 : 240347779 : insn_last_address = insn_current_address;
1979 : : }
1980 : :
1981 : 240347779 : dump_basic_block_info (file, insn, start_to_bb, end_to_bb,
1982 : : bb_map_size, &bb_seqn);
1983 : 240347779 : insn = final_scan_insn (insn, file, optimize_p, 0, &seen);
1984 : : }
1985 : :
1986 : 1437595 : maybe_output_next_view (&seen);
1987 : :
1988 : 1437595 : 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 : 241785374 : for (insn = first; insn; insn = next)
1996 : : {
1997 : 240347779 : next = NEXT_INSN (insn);
1998 : 240347779 : if (NOTE_P (insn)
1999 : 139411386 : && (NOTE_KIND (insn) == NOTE_INSN_CFI
2000 : 139411386 : || NOTE_KIND (insn) == NOTE_INSN_CFI_LABEL))
2001 : 11695538 : delete_insn (insn);
2002 : : }
2003 : 1437595 : }
2004 : :
2005 : : /* This is an exported final_1, callable without SEEN. */
2006 : :
2007 : : void
2008 : 1752 : 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 : 1752 : while (in_initial_view_p (first))
2017 : 0 : first = NEXT_INSN (first);
2018 : :
2019 : 1752 : final_1 (first, file, 0, optimize_p);
2020 : 1752 : }
2021 : :
2022 : : const char *
2023 : 88788972 : get_insn_template (int code, rtx_insn *insn)
2024 : : {
2025 : 88788972 : switch (insn_data[code].output_format)
2026 : : {
2027 : 17274256 : case INSN_OUTPUT_FORMAT_SINGLE:
2028 : 17274256 : return insn_data[code].output.single;
2029 : 9909635 : case INSN_OUTPUT_FORMAT_MULTI:
2030 : 9909635 : return insn_data[code].output.multi[which_alternative];
2031 : 61605081 : case INSN_OUTPUT_FORMAT_FUNCTION:
2032 : 61605081 : gcc_assert (insn);
2033 : 61605081 : 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 : 5909655 : call_from_call_insn (rtx_call_insn *insn)
2076 : : {
2077 : 5909655 : rtx x;
2078 : 5909655 : gcc_assert (CALL_P (insn));
2079 : 5909655 : x = PATTERN (insn);
2080 : :
2081 : 8479741 : while (GET_CODE (x) != CALL)
2082 : : {
2083 : 2570086 : 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 : 241382 : case PARALLEL:
2091 : 241382 : x = XVECEXP (x, 0, 0);
2092 : 241382 : break;
2093 : 2328704 : case SET:
2094 : 2328704 : x = XEXP (x, 1);
2095 : 2328704 : break;
2096 : : }
2097 : : }
2098 : 5909655 : return x;
2099 : : }
2100 : :
2101 : : /* Print a comment into the asm showing FILENAME, LINENUM, and the
2102 : : corresponding source line, if available. */
2103 : :
2104 : : static void
2105 : 32 : asm_show_source (const char *filename, int linenum)
2106 : : {
2107 : 32 : if (!filename)
2108 : 0 : return;
2109 : :
2110 : 32 : char_span line
2111 : 32 : = global_dc->get_file_cache ().get_source_line (filename, linenum);
2112 : 32 : if (!line)
2113 : : return;
2114 : :
2115 : 32 : fprintf (asm_out_file, "%s %s:%i: ", ASM_COMMENT_START, filename, linenum);
2116 : : /* "line" is not 0-terminated, so we must use its length. */
2117 : 32 : fwrite (line.get_buffer (), 1, line.length (), asm_out_file);
2118 : 32 : fputc ('\n', asm_out_file);
2119 : : }
2120 : :
2121 : : /* Judge if an absolute jump table is relocatable. */
2122 : :
2123 : : bool
2124 : 13144 : jumptable_relocatable (void)
2125 : : {
2126 : 13144 : bool relocatable = false;
2127 : :
2128 : 13144 : if (!CASE_VECTOR_PC_RELATIVE
2129 : 13144 : && !targetm.asm_out.generate_pic_addr_diff_vec ()
2130 : 13144 : && targetm_common.have_named_sections)
2131 : 11076 : relocatable = targetm.asm_out.reloc_rw_mask ();
2132 : :
2133 : 13144 : return relocatable;
2134 : : }
2135 : :
2136 : : /* The final scan for one insn, INSN.
2137 : : Args are same as in `final', except that INSN
2138 : : is the insn being scanned.
2139 : : Value returned is the next insn to be scanned.
2140 : :
2141 : : NOPEEPHOLES is the flag to disallow peephole processing (currently
2142 : : used for within delayed branch sequence output).
2143 : :
2144 : : SEEN is used to track the end of the prologue, for emitting
2145 : : debug information. We force the emission of a line note after
2146 : : both NOTE_INSN_PROLOGUE_END and NOTE_INSN_FUNCTION_BEG. */
2147 : :
2148 : : static rtx_insn *
2149 : 241743531 : final_scan_insn_1 (rtx_insn *insn, FILE *file, int optimize_p ATTRIBUTE_UNUSED,
2150 : : int nopeepholes ATTRIBUTE_UNUSED, int *seen)
2151 : : {
2152 : 241743531 : rtx_insn *next;
2153 : 241743531 : rtx_jump_table_data *table;
2154 : :
2155 : 241743531 : insn_counter++;
2156 : :
2157 : : /* Ignore deleted insns. These can occur when we split insns (due to a
2158 : : template of "#") while not optimizing. */
2159 : 241743531 : if (insn->deleted ())
2160 : 0 : return NEXT_INSN (insn);
2161 : :
2162 : 241743531 : switch (GET_CODE (insn))
2163 : : {
2164 : 140807138 : case NOTE:
2165 : 140807138 : switch (NOTE_KIND (insn))
2166 : : {
2167 : : case NOTE_INSN_DELETED:
2168 : : case NOTE_INSN_UPDATE_SJLJ_CONTEXT:
2169 : : break;
2170 : :
2171 : 61869 : case NOTE_INSN_SWITCH_TEXT_SECTIONS:
2172 : 61869 : maybe_output_next_view (seen);
2173 : :
2174 : 61869 : output_function_exception_table (0);
2175 : :
2176 : 61869 : if (targetm.asm_out.unwind_emit)
2177 : 0 : targetm.asm_out.unwind_emit (asm_out_file, insn);
2178 : :
2179 : 61869 : in_cold_section_p = !in_cold_section_p;
2180 : :
2181 : 61869 : gcc_checking_assert (in_cold_section_p);
2182 : 61869 : if (in_cold_section_p)
2183 : 61869 : cold_function_name
2184 : 61869 : = clone_function_name (current_function_decl, "cold");
2185 : :
2186 : 61869 : if (dwarf2out_do_frame ())
2187 : : {
2188 : 61867 : dwarf2out_switch_text_section ();
2189 : 61867 : if (!dwarf2_debug_info_emitted_p (current_function_decl)
2190 : 61867 : && !DECL_IGNORED_P (current_function_decl))
2191 : 41401 : debug_hooks->switch_text_section ();
2192 : : }
2193 : 2 : else if (!DECL_IGNORED_P (current_function_decl))
2194 : 1 : debug_hooks->switch_text_section ();
2195 : 62007 : if (DECL_IGNORED_P (current_function_decl) && last_linenum
2196 : 62007 : && last_filename)
2197 : 138 : debug_hooks->set_ignored_loc (last_linenum, last_columnnum,
2198 : : last_filename);
2199 : :
2200 : 61869 : switch_to_section (current_function_section ());
2201 : 61869 : targetm.asm_out.function_switched_text_sections (asm_out_file,
2202 : : current_function_decl,
2203 : : in_cold_section_p);
2204 : : /* Emit a label for the split cold section. Form label name by
2205 : : suffixing "cold" to the original function's name. */
2206 : 61869 : if (in_cold_section_p)
2207 : : {
2208 : : #ifdef ASM_DECLARE_COLD_FUNCTION_NAME
2209 : 61869 : ASM_DECLARE_COLD_FUNCTION_NAME (asm_out_file,
2210 : : IDENTIFIER_POINTER
2211 : : (cold_function_name),
2212 : : current_function_decl);
2213 : : #else
2214 : : ASM_OUTPUT_LABEL (asm_out_file,
2215 : : IDENTIFIER_POINTER (cold_function_name));
2216 : : #endif
2217 : 61869 : if (dwarf2out_do_frame ()
2218 : 61869 : && cfun->fde->dw_fde_second_begin != NULL)
2219 : 61867 : ASM_OUTPUT_LABEL (asm_out_file, cfun->fde->dw_fde_second_begin);
2220 : : }
2221 : : break;
2222 : :
2223 : 13517313 : case NOTE_INSN_BASIC_BLOCK:
2224 : 13517313 : if (need_profile_function)
2225 : : {
2226 : 24 : profile_function (asm_out_file);
2227 : 24 : need_profile_function = false;
2228 : : }
2229 : :
2230 : 13517313 : if (targetm.asm_out.unwind_emit)
2231 : 0 : targetm.asm_out.unwind_emit (asm_out_file, insn);
2232 : :
2233 : : break;
2234 : :
2235 : 394142 : case NOTE_INSN_EH_REGION_BEG:
2236 : 394142 : ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LEHB",
2237 : : NOTE_EH_HANDLER (insn));
2238 : 394142 : break;
2239 : :
2240 : 394142 : case NOTE_INSN_EH_REGION_END:
2241 : 394142 : ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LEHE",
2242 : : NOTE_EH_HANDLER (insn));
2243 : 394142 : break;
2244 : :
2245 : 1437595 : case NOTE_INSN_PROLOGUE_END:
2246 : 1437595 : targetm.asm_out.function_end_prologue (file);
2247 : 1437595 : profile_after_prologue (file);
2248 : :
2249 : 1437595 : if ((*seen & (SEEN_EMITTED | SEEN_NOTE)) == SEEN_NOTE)
2250 : : {
2251 : 609962 : *seen |= SEEN_EMITTED;
2252 : 609962 : force_source_line = true;
2253 : : }
2254 : : else
2255 : 827633 : *seen |= SEEN_NOTE;
2256 : :
2257 : : break;
2258 : :
2259 : 1553833 : case NOTE_INSN_EPILOGUE_BEG:
2260 : 1553833 : if (!DECL_IGNORED_P (current_function_decl))
2261 : 1533053 : (*debug_hooks->begin_epilogue) (last_linenum, last_filename);
2262 : 1553833 : targetm.asm_out.function_begin_epilogue (file);
2263 : 1553833 : break;
2264 : :
2265 : 11689582 : case NOTE_INSN_CFI:
2266 : 11689582 : dwarf2out_emit_cfi (NOTE_CFI (insn));
2267 : 11689582 : break;
2268 : :
2269 : 5956 : case NOTE_INSN_CFI_LABEL:
2270 : 5956 : ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LCFI",
2271 : : NOTE_LABEL_NUMBER (insn));
2272 : 5956 : break;
2273 : :
2274 : 1435843 : case NOTE_INSN_FUNCTION_BEG:
2275 : 1435843 : if (need_profile_function)
2276 : : {
2277 : 0 : profile_function (asm_out_file);
2278 : 0 : need_profile_function = false;
2279 : : }
2280 : :
2281 : 1435843 : app_disable ();
2282 : 1435843 : if (!DECL_IGNORED_P (current_function_decl))
2283 : 1412566 : debug_hooks->end_prologue (last_linenum, last_filename);
2284 : :
2285 : 1435843 : if ((*seen & (SEEN_EMITTED | SEEN_NOTE)) == SEEN_NOTE)
2286 : : {
2287 : 825881 : *seen |= SEEN_EMITTED;
2288 : 825881 : force_source_line = true;
2289 : : }
2290 : : else
2291 : 609962 : *seen |= SEEN_NOTE;
2292 : :
2293 : : break;
2294 : :
2295 : 20710432 : case NOTE_INSN_BLOCK_BEG:
2296 : 20710432 : if (debug_info_level >= DINFO_LEVEL_NORMAL
2297 : 31454 : || dwarf_debuginfo_p ()
2298 : 20710432 : || write_symbols == VMS_DEBUG)
2299 : : {
2300 : 20710432 : int n = BLOCK_NUMBER (NOTE_BLOCK (insn));
2301 : :
2302 : 20710432 : app_disable ();
2303 : 20710432 : ++block_depth;
2304 : 20710432 : high_block_linenum = last_linenum;
2305 : :
2306 : : /* Output debugging info about the symbol-block beginning. */
2307 : 20710432 : if (!DECL_IGNORED_P (current_function_decl))
2308 : 20710432 : debug_hooks->begin_block (last_linenum, n, NOTE_BLOCK (insn));
2309 : :
2310 : : /* Mark this block as output. */
2311 : 20710432 : TREE_ASM_WRITTEN (NOTE_BLOCK (insn)) = 1;
2312 : 20710432 : BLOCK_IN_COLD_SECTION_P (NOTE_BLOCK (insn)) = in_cold_section_p;
2313 : : }
2314 : : break;
2315 : :
2316 : 20710432 : case NOTE_INSN_BLOCK_END:
2317 : 20710432 : maybe_output_next_view (seen);
2318 : :
2319 : 20710432 : if (debug_info_level >= DINFO_LEVEL_NORMAL
2320 : 31454 : || dwarf_debuginfo_p ()
2321 : 20710432 : || write_symbols == VMS_DEBUG)
2322 : : {
2323 : 20710432 : int n = BLOCK_NUMBER (NOTE_BLOCK (insn));
2324 : :
2325 : 20710432 : app_disable ();
2326 : :
2327 : : /* End of a symbol-block. */
2328 : 20710432 : --block_depth;
2329 : 20710432 : gcc_assert (block_depth >= 0);
2330 : :
2331 : 20710432 : if (!DECL_IGNORED_P (current_function_decl))
2332 : 20710432 : debug_hooks->end_block (high_block_linenum, n);
2333 : 20710432 : gcc_assert (BLOCK_IN_COLD_SECTION_P (NOTE_BLOCK (insn))
2334 : : == in_cold_section_p);
2335 : : }
2336 : : break;
2337 : :
2338 : 46479 : case NOTE_INSN_DELETED_LABEL:
2339 : : /* Emit the label. We may have deleted the CODE_LABEL because
2340 : : the label could be proved to be unreachable, though still
2341 : : referenced (in the form of having its address taken. */
2342 : 46479 : ASM_OUTPUT_DEBUG_LABEL (file, "L", CODE_LABEL_NUMBER (insn));
2343 : 46479 : break;
2344 : :
2345 : 7522 : case NOTE_INSN_DELETED_DEBUG_LABEL:
2346 : : /* Similarly, but need to use different namespace for it. */
2347 : 7522 : if (CODE_LABEL_NUMBER (insn) != -1)
2348 : 7522 : ASM_OUTPUT_DEBUG_LABEL (file, "LDL", CODE_LABEL_NUMBER (insn));
2349 : : break;
2350 : :
2351 : 50493420 : case NOTE_INSN_VAR_LOCATION:
2352 : 50493420 : if (!DECL_IGNORED_P (current_function_decl))
2353 : : {
2354 : 50459192 : debug_hooks->var_location (insn);
2355 : 50459192 : set_next_view_needed (seen);
2356 : : }
2357 : : break;
2358 : :
2359 : 3846779 : case NOTE_INSN_BEGIN_STMT:
2360 : 3846779 : gcc_checking_assert (cfun->debug_nonbind_markers);
2361 : 3846779 : if (!DECL_IGNORED_P (current_function_decl)
2362 : 3846779 : && notice_source_line (insn, NULL))
2363 : : {
2364 : 9989650 : output_source_line:
2365 : 9989650 : (*debug_hooks->source_line) (last_linenum, last_columnnum,
2366 : : last_filename, last_discriminator,
2367 : : true);
2368 : 9989650 : clear_next_view_needed (seen);
2369 : : }
2370 : : break;
2371 : :
2372 : 6142871 : case NOTE_INSN_INLINE_ENTRY:
2373 : 6142871 : gcc_checking_assert (cfun->debug_nonbind_markers);
2374 : 6142871 : if (!DECL_IGNORED_P (current_function_decl)
2375 : 6142871 : && notice_source_line (insn, NULL))
2376 : : {
2377 : 6142871 : (*debug_hooks->inline_entry) (LOCATION_BLOCK
2378 : : (NOTE_MARKER_LOCATION (insn)));
2379 : 6142871 : goto output_source_line;
2380 : : }
2381 : : break;
2382 : :
2383 : 0 : default:
2384 : 0 : gcc_unreachable ();
2385 : : break;
2386 : : }
2387 : : break;
2388 : :
2389 : : case BARRIER:
2390 : : break;
2391 : :
2392 : 6492013 : case CODE_LABEL:
2393 : : /* The target port might emit labels in the output function for
2394 : : some insn, e.g. sh.cc output_branchy_insn. */
2395 : 6492013 : if (CODE_LABEL_NUMBER (insn) <= max_labelno)
2396 : : {
2397 : 6492011 : align_flags alignment = LABEL_TO_ALIGNMENT (insn);
2398 : 7700910 : if (alignment.levels[0].log && NEXT_INSN (insn))
2399 : : {
2400 : : #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
2401 : : /* Output both primary and secondary alignment. */
2402 : 1208899 : ASM_OUTPUT_MAX_SKIP_ALIGN (file, alignment.levels[0].log,
2403 : : alignment.levels[0].maxskip);
2404 : 1208899 : ASM_OUTPUT_MAX_SKIP_ALIGN (file, alignment.levels[1].log,
2405 : : alignment.levels[1].maxskip);
2406 : : #else
2407 : : #ifdef ASM_OUTPUT_ALIGN_WITH_NOP
2408 : : ASM_OUTPUT_ALIGN_WITH_NOP (file, alignment.levels[0].log);
2409 : : #else
2410 : : ASM_OUTPUT_ALIGN (file, alignment.levels[0].log);
2411 : : #endif
2412 : : #endif
2413 : : }
2414 : : }
2415 : 6492013 : CC_STATUS_INIT;
2416 : :
2417 : 6492013 : if (!DECL_IGNORED_P (current_function_decl) && LABEL_NAME (insn))
2418 : 53663 : debug_hooks->label (as_a <rtx_code_label *> (insn));
2419 : :
2420 : 6492013 : app_disable ();
2421 : :
2422 : : /* If this label is followed by a jump-table, make sure we put
2423 : : the label in the read-only section. Also possibly write the
2424 : : label and jump table together. */
2425 : 6492013 : table = jump_table_for_label (as_a <rtx_code_label *> (insn));
2426 : 6492013 : if (table)
2427 : : {
2428 : : #if defined(ASM_OUTPUT_ADDR_VEC) || defined(ASM_OUTPUT_ADDR_DIFF_VEC)
2429 : : /* In this case, the case vector is being moved by the
2430 : : target, so don't output the label at all. Leave that
2431 : : to the back end macros. */
2432 : : #else
2433 : 6572 : if (! JUMP_TABLES_IN_TEXT_SECTION)
2434 : : {
2435 : 6572 : int log_align;
2436 : :
2437 : 6572 : switch_to_section (targetm.asm_out.function_rodata_section
2438 : : (current_function_decl,
2439 : 6572 : jumptable_relocatable ()));
2440 : :
2441 : : #ifdef ADDR_VEC_ALIGN
2442 : 6572 : log_align = ADDR_VEC_ALIGN (table);
2443 : : #else
2444 : : log_align = exact_log2 (BIGGEST_ALIGNMENT / BITS_PER_UNIT);
2445 : : #endif
2446 : 6572 : ASM_OUTPUT_ALIGN (file, log_align);
2447 : : }
2448 : : else
2449 : : switch_to_section (current_function_section ());
2450 : :
2451 : : #ifdef ASM_OUTPUT_CASE_LABEL
2452 : 6572 : ASM_OUTPUT_CASE_LABEL (file, "L", CODE_LABEL_NUMBER (insn), table);
2453 : : #else
2454 : : targetm.asm_out.internal_label (file, "L", CODE_LABEL_NUMBER (insn));
2455 : : #endif
2456 : : #endif
2457 : 6572 : break;
2458 : : }
2459 : 6485441 : if (LABEL_ALT_ENTRY_P (insn))
2460 : 0 : output_alternate_entry_point (file, insn);
2461 : : else
2462 : 6485441 : targetm.asm_out.internal_label (file, "L", CODE_LABEL_NUMBER (insn));
2463 : : break;
2464 : :
2465 : 89936767 : default:
2466 : 89936767 : {
2467 : 89936767 : rtx body = PATTERN (insn);
2468 : 89936767 : int insn_code_number;
2469 : 89936767 : const char *templ;
2470 : 89936767 : bool is_stmt, *is_stmt_p;
2471 : :
2472 : 89936767 : if (MAY_HAVE_DEBUG_MARKER_INSNS && cfun->debug_nonbind_markers)
2473 : : {
2474 : 19341736 : is_stmt = false;
2475 : 19341736 : is_stmt_p = NULL;
2476 : : }
2477 : : else
2478 : : is_stmt_p = &is_stmt;
2479 : :
2480 : : /* Reset this early so it is correct for ASM statements. */
2481 : 89936767 : current_insn_predicate = NULL_RTX;
2482 : :
2483 : : /* An INSN, JUMP_INSN or CALL_INSN.
2484 : : First check for special kinds that recog doesn't recognize. */
2485 : :
2486 : 89936767 : if (GET_CODE (body) == USE /* These are just declarations. */
2487 : 89936767 : || GET_CODE (body) == CLOBBER)
2488 : : break;
2489 : :
2490 : : /* Detect insns that are really jump-tables
2491 : : and output them as such. */
2492 : :
2493 : 88901789 : if (JUMP_TABLE_DATA_P (insn))
2494 : : {
2495 : : #if !(defined(ASM_OUTPUT_ADDR_VEC) || defined(ASM_OUTPUT_ADDR_DIFF_VEC))
2496 : 6572 : int vlen, idx;
2497 : : #endif
2498 : :
2499 : 6572 : if (! JUMP_TABLES_IN_TEXT_SECTION)
2500 : 6572 : switch_to_section (targetm.asm_out.function_rodata_section
2501 : : (current_function_decl,
2502 : 6572 : jumptable_relocatable ()));
2503 : : else
2504 : : switch_to_section (current_function_section ());
2505 : :
2506 : 6572 : app_disable ();
2507 : :
2508 : : #if defined(ASM_OUTPUT_ADDR_VEC) || defined(ASM_OUTPUT_ADDR_DIFF_VEC)
2509 : : if (GET_CODE (body) == ADDR_VEC)
2510 : : {
2511 : : #ifdef ASM_OUTPUT_ADDR_VEC
2512 : : ASM_OUTPUT_ADDR_VEC (PREV_INSN (insn), body);
2513 : : #else
2514 : : gcc_unreachable ();
2515 : : #endif
2516 : : }
2517 : : else
2518 : : {
2519 : : #ifdef ASM_OUTPUT_ADDR_DIFF_VEC
2520 : : ASM_OUTPUT_ADDR_DIFF_VEC (PREV_INSN (insn), body);
2521 : : #else
2522 : : gcc_unreachable ();
2523 : : #endif
2524 : : }
2525 : : #else
2526 : 6572 : vlen = XVECLEN (body, GET_CODE (body) == ADDR_DIFF_VEC);
2527 : 176614 : for (idx = 0; idx < vlen; idx++)
2528 : : {
2529 : 170042 : if (GET_CODE (body) == ADDR_VEC)
2530 : : {
2531 : : #ifdef ASM_OUTPUT_ADDR_VEC_ELT
2532 : 144809 : ASM_OUTPUT_ADDR_VEC_ELT
2533 : : (file, CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 0, idx), 0)));
2534 : : #else
2535 : : gcc_unreachable ();
2536 : : #endif
2537 : : }
2538 : : else
2539 : : {
2540 : : #ifdef ASM_OUTPUT_ADDR_DIFF_ELT
2541 : 25233 : ASM_OUTPUT_ADDR_DIFF_ELT
2542 : : (file,
2543 : : body,
2544 : : CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 1, idx), 0)),
2545 : : CODE_LABEL_NUMBER (XEXP (XEXP (body, 0), 0)));
2546 : : #else
2547 : : gcc_unreachable ();
2548 : : #endif
2549 : : }
2550 : : }
2551 : : #ifdef ASM_OUTPUT_CASE_END
2552 : : ASM_OUTPUT_CASE_END (file,
2553 : : CODE_LABEL_NUMBER (PREV_INSN (insn)),
2554 : : insn);
2555 : : #endif
2556 : : #endif
2557 : :
2558 : 6572 : switch_to_section (current_function_section ());
2559 : :
2560 : 6572 : if (debug_variable_location_views
2561 : 6572 : && !DECL_IGNORED_P (current_function_decl))
2562 : 5701 : debug_hooks->var_location (insn);
2563 : :
2564 : : break;
2565 : : }
2566 : : /* Output this line note if it is the first or the last line
2567 : : note in a row. */
2568 : 88895217 : if (!DECL_IGNORED_P (current_function_decl)
2569 : 88895217 : && notice_source_line (insn, is_stmt_p))
2570 : : {
2571 : 25682119 : if (flag_verbose_asm)
2572 : 32 : asm_show_source (last_filename, last_linenum);
2573 : 25682119 : (*debug_hooks->source_line) (last_linenum, last_columnnum,
2574 : : last_filename, last_discriminator,
2575 : : is_stmt);
2576 : 25682119 : clear_next_view_needed (seen);
2577 : : }
2578 : : else
2579 : 63213098 : maybe_output_next_view (seen);
2580 : :
2581 : 88895217 : gcc_checking_assert (!DEBUG_INSN_P (insn));
2582 : :
2583 : 88895217 : if (GET_CODE (body) == PARALLEL
2584 : 11286790 : && GET_CODE (XVECEXP (body, 0, 0)) == ASM_INPUT)
2585 : 88895217 : body = XVECEXP (body, 0, 0);
2586 : :
2587 : 88895217 : if (GET_CODE (body) == ASM_INPUT)
2588 : : {
2589 : 3021 : const char *string = XSTR (body, 0);
2590 : :
2591 : : /* There's no telling what that did to the condition codes. */
2592 : 3021 : CC_STATUS_INIT;
2593 : :
2594 : 3021 : if (string[0])
2595 : : {
2596 : 944 : expanded_location loc;
2597 : :
2598 : 944 : app_enable ();
2599 : 944 : loc = expand_location (ASM_INPUT_SOURCE_LOCATION (body));
2600 : 944 : if (*loc.file && loc.line)
2601 : 944 : fprintf (asm_out_file, "%s %i \"%s\" 1\n",
2602 : : ASM_COMMENT_START, loc.line, loc.file);
2603 : 944 : fprintf (asm_out_file, "\t%s\n", string);
2604 : : #if HAVE_AS_LINE_ZERO
2605 : 944 : if (*loc.file && loc.line)
2606 : 944 : fprintf (asm_out_file, "%s 0 \"\" 2\n", ASM_COMMENT_START);
2607 : : #endif
2608 : : }
2609 : : break;
2610 : : }
2611 : :
2612 : : /* Detect `asm' construct with operands. */
2613 : 88892196 : if (asm_noperands (body) >= 0)
2614 : : {
2615 : 103283 : unsigned int noperands = asm_noperands (body);
2616 : 103283 : rtx *ops = XALLOCAVEC (rtx, noperands);
2617 : 103283 : const char *string;
2618 : 103283 : location_t loc;
2619 : 103283 : expanded_location expanded;
2620 : :
2621 : : /* There's no telling what that did to the condition codes. */
2622 : 103283 : CC_STATUS_INIT;
2623 : :
2624 : : /* Get out the operand values. */
2625 : 103283 : string = decode_asm_operands (body, ops, NULL, NULL, NULL, &loc);
2626 : : /* Inhibit dying on what would otherwise be compiler bugs. */
2627 : 103283 : insn_noperands = noperands;
2628 : 103283 : this_is_asm_operands = insn;
2629 : 103283 : expanded = expand_location (loc);
2630 : :
2631 : : #ifdef FINAL_PRESCAN_INSN
2632 : : FINAL_PRESCAN_INSN (insn, ops, insn_noperands);
2633 : : #endif
2634 : :
2635 : : /* Output the insn using them. */
2636 : 103283 : if (string[0])
2637 : : {
2638 : 34077 : app_enable ();
2639 : 34077 : if (expanded.file && expanded.line)
2640 : 34047 : fprintf (asm_out_file, "%s %i \"%s\" 1\n",
2641 : : ASM_COMMENT_START, expanded.line, expanded.file);
2642 : 34077 : output_asm_insn (string, ops);
2643 : : #if HAVE_AS_LINE_ZERO
2644 : 34077 : if (expanded.file && expanded.line)
2645 : 34047 : fprintf (asm_out_file, "%s 0 \"\" 2\n", ASM_COMMENT_START);
2646 : : #endif
2647 : : }
2648 : :
2649 : 103283 : if (targetm.asm_out.final_postscan_insn)
2650 : 0 : targetm.asm_out.final_postscan_insn (file, insn, ops,
2651 : : insn_noperands);
2652 : :
2653 : 103283 : this_is_asm_operands = 0;
2654 : 103283 : break;
2655 : : }
2656 : :
2657 : 88788913 : app_disable ();
2658 : :
2659 : 88788913 : if (rtx_sequence *seq = dyn_cast <rtx_sequence *> (body))
2660 : : {
2661 : : /* A delayed-branch sequence */
2662 : 0 : int i;
2663 : :
2664 : 0 : final_sequence = seq;
2665 : :
2666 : : /* The first insn in this SEQUENCE might be a JUMP_INSN that will
2667 : : force the restoration of a comparison that was previously
2668 : : thought unnecessary. If that happens, cancel this sequence
2669 : : and cause that insn to be restored. */
2670 : :
2671 : 0 : next = final_scan_insn (seq->insn (0), file, 0, 1, seen);
2672 : 0 : if (next != seq->insn (1))
2673 : : {
2674 : 0 : final_sequence = 0;
2675 : 0 : return next;
2676 : : }
2677 : :
2678 : 0 : for (i = 1; i < seq->len (); i++)
2679 : : {
2680 : 0 : rtx_insn *insn = seq->insn (i);
2681 : 0 : rtx_insn *next = NEXT_INSN (insn);
2682 : : /* We loop in case any instruction in a delay slot gets
2683 : : split. */
2684 : 0 : do
2685 : 0 : insn = final_scan_insn (insn, file, 0, 1, seen);
2686 : 0 : while (insn != next);
2687 : : }
2688 : : #ifdef DBR_OUTPUT_SEQEND
2689 : : DBR_OUTPUT_SEQEND (file);
2690 : : #endif
2691 : 0 : final_sequence = 0;
2692 : :
2693 : : /* If the insn requiring the delay slot was a CALL_INSN, the
2694 : : insns in the delay slot are actually executed before the
2695 : : called function. Hence we don't preserve any CC-setting
2696 : : actions in these insns and the CC must be marked as being
2697 : : clobbered by the function. */
2698 : 0 : if (CALL_P (seq->insn (0)))
2699 : : {
2700 : 0 : CC_STATUS_INIT;
2701 : : }
2702 : 0 : break;
2703 : : }
2704 : :
2705 : : /* We have a real machine instruction as rtl. */
2706 : :
2707 : 88788913 : body = PATTERN (insn);
2708 : :
2709 : : /* Do machine-specific peephole optimizations if desired. */
2710 : :
2711 : 88788913 : if (HAVE_peephole && optimize_p && !flag_no_peephole && !nopeepholes)
2712 : : {
2713 : : rtx_insn *next = peephole (insn);
2714 : : /* When peepholing, if there were notes within the peephole,
2715 : : emit them before the peephole. */
2716 : : if (next != 0 && next != NEXT_INSN (insn))
2717 : : {
2718 : : rtx_insn *note, *prev = PREV_INSN (insn);
2719 : :
2720 : : for (note = NEXT_INSN (insn); note != next;
2721 : : note = NEXT_INSN (note))
2722 : : final_scan_insn (note, file, optimize_p, nopeepholes, seen);
2723 : :
2724 : : /* Put the notes in the proper position for a later
2725 : : rescan. For example, the SH target can do this
2726 : : when generating a far jump in a delayed branch
2727 : : sequence. */
2728 : : note = NEXT_INSN (insn);
2729 : : SET_PREV_INSN (note) = prev;
2730 : : SET_NEXT_INSN (prev) = note;
2731 : : SET_NEXT_INSN (PREV_INSN (next)) = insn;
2732 : : SET_PREV_INSN (insn) = PREV_INSN (next);
2733 : : SET_NEXT_INSN (insn) = next;
2734 : : SET_PREV_INSN (next) = insn;
2735 : : }
2736 : :
2737 : : /* PEEPHOLE might have changed this. */
2738 : : body = PATTERN (insn);
2739 : : }
2740 : :
2741 : : /* Try to recognize the instruction.
2742 : : If successful, verify that the operands satisfy the
2743 : : constraints for the instruction. Crash if they don't,
2744 : : since `reload' should have changed them so that they do. */
2745 : :
2746 : 88788913 : insn_code_number = recog_memoized (insn);
2747 : 88788913 : cleanup_subreg_operands (insn);
2748 : :
2749 : : /* Dump the insn in the assembly for debugging (-dAP).
2750 : : If the final dump is requested as slim RTL, dump slim
2751 : : RTL to the assembly file also. */
2752 : 88788913 : if (flag_dump_rtl_in_asm)
2753 : : {
2754 : 29 : print_rtx_head = ASM_COMMENT_START;
2755 : 29 : if (! (dump_flags & TDF_SLIM))
2756 : 29 : print_rtl_single (asm_out_file, insn);
2757 : : else
2758 : 0 : dump_insn_slim (asm_out_file, insn);
2759 : 29 : print_rtx_head = "";
2760 : : }
2761 : :
2762 : 88788913 : if (! constrain_operands_cached (insn, 1))
2763 : 0 : fatal_insn_not_found (insn);
2764 : :
2765 : : /* Some target machines need to prescan each insn before
2766 : : it is output. */
2767 : :
2768 : : #ifdef FINAL_PRESCAN_INSN
2769 : : FINAL_PRESCAN_INSN (insn, recog_data.operand, recog_data.n_operands);
2770 : : #endif
2771 : :
2772 : 88788913 : if (targetm.have_conditional_execution ()
2773 : 88788913 : && GET_CODE (PATTERN (insn)) == COND_EXEC)
2774 : 0 : current_insn_predicate = COND_EXEC_TEST (PATTERN (insn));
2775 : :
2776 : 88788913 : current_output_insn = debug_insn = insn;
2777 : :
2778 : : /* Find the proper template for this insn. */
2779 : 88788913 : templ = get_insn_template (insn_code_number, insn);
2780 : :
2781 : : /* If the C code returns 0, it means that it is a jump insn
2782 : : which follows a deleted test insn, and that test insn
2783 : : needs to be reinserted. */
2784 : 88788913 : if (templ == 0)
2785 : : {
2786 : 0 : rtx_insn *prev;
2787 : :
2788 : 0 : gcc_assert (prev_nonnote_insn (insn) == last_ignored_compare);
2789 : :
2790 : : /* We have already processed the notes between the setter and
2791 : : the user. Make sure we don't process them again, this is
2792 : : particularly important if one of the notes is a block
2793 : : scope note or an EH note. */
2794 : 0 : for (prev = insn;
2795 : 0 : prev != last_ignored_compare;
2796 : 0 : prev = PREV_INSN (prev))
2797 : : {
2798 : 0 : if (NOTE_P (prev))
2799 : 0 : delete_insn (prev); /* Use delete_note. */
2800 : : }
2801 : :
2802 : : return prev;
2803 : : }
2804 : :
2805 : : /* If the template is the string "#", it means that this insn must
2806 : : be split. */
2807 : 88788913 : if (templ[0] == '#' && templ[1] == '\0')
2808 : : {
2809 : 0 : rtx_insn *new_rtx = try_split (body, insn, 0);
2810 : :
2811 : : /* If we didn't split the insn, go away. */
2812 : 0 : if (new_rtx == insn && PATTERN (new_rtx) == body)
2813 : 0 : fatal_insn ("could not split insn", insn);
2814 : :
2815 : : /* If we have a length attribute, this instruction should have
2816 : : been split in shorten_branches, to ensure that we would have
2817 : : valid length info for the splitees. */
2818 : 0 : gcc_assert (!HAVE_ATTR_length);
2819 : :
2820 : : return new_rtx;
2821 : : }
2822 : :
2823 : : /* ??? This will put the directives in the wrong place if
2824 : : get_insn_template outputs assembly directly. However calling it
2825 : : before get_insn_template breaks if the insns is split. */
2826 : 88788913 : if (targetm.asm_out.unwind_emit_before_insn
2827 : 88788913 : && targetm.asm_out.unwind_emit)
2828 : 0 : targetm.asm_out.unwind_emit (asm_out_file, insn);
2829 : :
2830 : 88788913 : rtx_call_insn *call_insn = dyn_cast <rtx_call_insn *> (insn);
2831 : 5909655 : if (call_insn != NULL)
2832 : : {
2833 : 5909655 : rtx x = call_from_call_insn (call_insn);
2834 : 5909655 : x = XEXP (x, 0);
2835 : 5909655 : if (x && MEM_P (x) && GET_CODE (XEXP (x, 0)) == SYMBOL_REF)
2836 : : {
2837 : 5712783 : tree t;
2838 : 5712783 : x = XEXP (x, 0);
2839 : 5712783 : t = SYMBOL_REF_DECL (x);
2840 : 5712783 : if (t)
2841 : 5450365 : assemble_external (t);
2842 : : }
2843 : : }
2844 : :
2845 : : /* Output assembler code from the template. */
2846 : 88788913 : output_asm_insn (templ, recog_data.operand);
2847 : :
2848 : : /* Some target machines need to postscan each insn after
2849 : : it is output. */
2850 : 88788913 : if (targetm.asm_out.final_postscan_insn)
2851 : 0 : targetm.asm_out.final_postscan_insn (file, insn, recog_data.operand,
2852 : 0 : recog_data.n_operands);
2853 : :
2854 : 88788913 : if (!targetm.asm_out.unwind_emit_before_insn
2855 : 0 : && targetm.asm_out.unwind_emit)
2856 : 0 : targetm.asm_out.unwind_emit (asm_out_file, insn);
2857 : :
2858 : : /* Let the debug info back-end know about this call. We do this only
2859 : : after the instruction has been emitted because labels that may be
2860 : : created to reference the call instruction must appear after it. */
2861 : 49279672 : if ((debug_variable_location_views || call_insn != NULL)
2862 : 91660524 : && !DECL_IGNORED_P (current_function_decl))
2863 : 42333640 : debug_hooks->var_location (insn);
2864 : :
2865 : 88788913 : current_output_insn = debug_insn = 0;
2866 : : }
2867 : : }
2868 : 241743531 : return NEXT_INSN (insn);
2869 : : }
2870 : :
2871 : : /* This is a wrapper around final_scan_insn_1 that allows ports to
2872 : : call it recursively without a known value for SEEN. The value is
2873 : : saved at the outermost call, and recovered for recursive calls.
2874 : : Recursive calls MUST pass NULL, or the same pointer if they can
2875 : : otherwise get to it. */
2876 : :
2877 : : rtx_insn *
2878 : 241743531 : final_scan_insn (rtx_insn *insn, FILE *file, int optimize_p,
2879 : : int nopeepholes, int *seen)
2880 : : {
2881 : 241743531 : static int *enclosing_seen;
2882 : 241743531 : static int recursion_counter;
2883 : :
2884 : 241743531 : gcc_assert (seen || recursion_counter);
2885 : 241743531 : gcc_assert (!recursion_counter || !seen || seen == enclosing_seen);
2886 : :
2887 : 241743531 : if (!recursion_counter++)
2888 : 241743531 : enclosing_seen = seen;
2889 : 0 : else if (!seen)
2890 : 0 : seen = enclosing_seen;
2891 : :
2892 : 241743531 : rtx_insn *ret = final_scan_insn_1 (insn, file, optimize_p, nopeepholes, seen);
2893 : :
2894 : 241743531 : if (!--recursion_counter)
2895 : 241743531 : enclosing_seen = NULL;
2896 : :
2897 : 241743531 : return ret;
2898 : : }
2899 : :
2900 : :
2901 : :
2902 : : /* Map DECLs to instance discriminators. This is allocated and
2903 : : defined in ada/gcc-interfaces/trans.cc, when compiling with -gnateS.
2904 : : Mappings from this table are saved and restored for LTO, so
2905 : : link-time compilation will have this map set, at least in
2906 : : partitions containing at least one DECL with an associated instance
2907 : : discriminator. */
2908 : :
2909 : : decl_to_instance_map_t *decl_to_instance_map;
2910 : :
2911 : : /* Return the instance number assigned to DECL. */
2912 : :
2913 : : static inline int
2914 : 0 : map_decl_to_instance (const_tree decl)
2915 : : {
2916 : 0 : int *inst;
2917 : :
2918 : 0 : if (!decl_to_instance_map || !decl || !DECL_P (decl))
2919 : : return 0;
2920 : :
2921 : 0 : inst = decl_to_instance_map->get (decl);
2922 : :
2923 : 0 : if (!inst)
2924 : : return 0;
2925 : :
2926 : 0 : return *inst;
2927 : : }
2928 : :
2929 : : /* Set DISCRIMINATOR to the appropriate value, possibly derived from LOC. */
2930 : :
2931 : : static inline int
2932 : 90718230 : compute_discriminator (location_t loc)
2933 : : {
2934 : 90718230 : int discriminator;
2935 : :
2936 : 90718230 : if (!decl_to_instance_map)
2937 : 90718230 : discriminator = get_discriminator_from_loc (loc);
2938 : : else
2939 : : {
2940 : 0 : tree block = LOCATION_BLOCK (loc);
2941 : :
2942 : 0 : while (block && TREE_CODE (block) == BLOCK
2943 : 0 : && !inlined_function_outer_scope_p (block))
2944 : 0 : block = BLOCK_SUPERCONTEXT (block);
2945 : :
2946 : 0 : tree decl;
2947 : :
2948 : 0 : if (!block)
2949 : 0 : decl = current_function_decl;
2950 : 0 : else if (DECL_P (block))
2951 : : decl = block;
2952 : : else
2953 : 0 : decl = block_ultimate_origin (block);
2954 : :
2955 : 0 : discriminator = map_decl_to_instance (decl);
2956 : : }
2957 : :
2958 : 90718230 : return discriminator;
2959 : : }
2960 : :
2961 : : /* Return discriminator of the statement that produced this insn. */
2962 : : int
2963 : 80728580 : insn_discriminator (const rtx_insn *insn)
2964 : : {
2965 : 80728580 : return compute_discriminator (INSN_LOCATION (insn));
2966 : : }
2967 : :
2968 : : /* Return whether a source line note needs to be emitted before INSN.
2969 : : Sets IS_STMT to TRUE if the line should be marked as a possible
2970 : : breakpoint location. */
2971 : :
2972 : : static bool
2973 : 98785965 : notice_source_line (rtx_insn *insn, bool *is_stmt)
2974 : : {
2975 : 98785965 : const char *filename;
2976 : 98785965 : int linenum, columnnum;
2977 : 98785965 : int discriminator;
2978 : :
2979 : 98785965 : if (NOTE_MARKER_P (insn))
2980 : : {
2981 : 9989650 : location_t loc = NOTE_MARKER_LOCATION (insn);
2982 : 9989650 : expanded_location xloc = expand_location (loc);
2983 : 9989650 : if (xloc.line == 0
2984 : 9989650 : && (LOCATION_LOCUS (loc) == UNKNOWN_LOCATION
2985 : 10 : || LOCATION_LOCUS (loc) == BUILTINS_LOCATION))
2986 : 0 : return false;
2987 : :
2988 : 9989650 : filename = xloc.file;
2989 : 9989650 : linenum = xloc.line;
2990 : 9989650 : columnnum = xloc.column;
2991 : 9989650 : discriminator = compute_discriminator (loc);
2992 : 9989650 : force_source_line = true;
2993 : 9989650 : }
2994 : 88796315 : else if (override_filename)
2995 : : {
2996 : 0 : filename = override_filename;
2997 : 0 : linenum = override_linenum;
2998 : 0 : columnnum = override_columnnum;
2999 : 0 : discriminator = override_discriminator;
3000 : : }
3001 : 88796315 : else if (INSN_HAS_LOCATION (insn))
3002 : : {
3003 : 80583018 : expanded_location xloc = insn_location (insn);
3004 : 80583018 : filename = xloc.file;
3005 : 80583018 : linenum = xloc.line;
3006 : 80583018 : columnnum = xloc.column;
3007 : 80583018 : discriminator = insn_discriminator (insn);
3008 : : }
3009 : : else
3010 : : {
3011 : : filename = NULL;
3012 : : linenum = 0;
3013 : : columnnum = 0;
3014 : : discriminator = 0;
3015 : : }
3016 : :
3017 : 90572668 : if (filename == NULL)
3018 : 8213297 : return false;
3019 : :
3020 : 90572668 : if (force_source_line
3021 : 79409731 : || filename != last_filename
3022 : 76744660 : || last_linenum != linenum
3023 : 65400556 : || (debug_column_info && last_columnnum != columnnum))
3024 : : {
3025 : 29463766 : force_source_line = false;
3026 : 29463766 : last_filename = filename;
3027 : 29463766 : last_linenum = linenum;
3028 : 29463766 : last_columnnum = columnnum;
3029 : 29463766 : last_discriminator = discriminator;
3030 : 29463766 : if (is_stmt)
3031 : 11839004 : *is_stmt = true;
3032 : 29463766 : high_block_linenum = MAX (last_linenum, high_block_linenum);
3033 : 29463766 : high_function_linenum = MAX (last_linenum, high_function_linenum);
3034 : 29463766 : return true;
3035 : : }
3036 : :
3037 : 61108902 : if (SUPPORTS_DISCRIMINATOR && last_discriminator != discriminator)
3038 : : {
3039 : : /* If the discriminator changed, but the line number did not,
3040 : : output the line table entry with is_stmt false so the
3041 : : debugger does not treat this as a breakpoint location. */
3042 : 6208003 : last_discriminator = discriminator;
3043 : 6208003 : if (is_stmt)
3044 : 5839242 : *is_stmt = false;
3045 : 6208003 : return true;
3046 : : }
3047 : :
3048 : : return false;
3049 : : }
3050 : :
3051 : : /* For each operand in INSN, simplify (subreg (reg)) so that it refers
3052 : : directly to the desired hard register. */
3053 : :
3054 : : void
3055 : 96999698 : cleanup_subreg_operands (rtx_insn *insn)
3056 : : {
3057 : 96999698 : int i;
3058 : 96999698 : bool changed = false;
3059 : 96999698 : extract_insn_cached (insn);
3060 : 396809247 : for (i = 0; i < recog_data.n_operands; i++)
3061 : : {
3062 : : /* The following test cannot use recog_data.operand when testing
3063 : : for a SUBREG: the underlying object might have been changed
3064 : : already if we are inside a match_operator expression that
3065 : : matches the else clause. Instead we test the underlying
3066 : : expression directly. */
3067 : 202809851 : if (GET_CODE (*recog_data.operand_loc[i]) == SUBREG)
3068 : : {
3069 : 176 : recog_data.operand[i] = alter_subreg (recog_data.operand_loc[i], true);
3070 : 176 : changed = true;
3071 : : }
3072 : 202809675 : else if (GET_CODE (recog_data.operand[i]) == PLUS
3073 : : || GET_CODE (recog_data.operand[i]) == MULT
3074 : : || MEM_P (recog_data.operand[i]))
3075 : 47461522 : recog_data.operand[i] = walk_alter_subreg (recog_data.operand_loc[i], &changed);
3076 : : }
3077 : :
3078 : 98964971 : for (i = 0; i < recog_data.n_dups; i++)
3079 : : {
3080 : 1965273 : if (GET_CODE (*recog_data.dup_loc[i]) == SUBREG)
3081 : : {
3082 : 0 : *recog_data.dup_loc[i] = alter_subreg (recog_data.dup_loc[i], true);
3083 : 0 : changed = true;
3084 : : }
3085 : 1965273 : else if (GET_CODE (*recog_data.dup_loc[i]) == PLUS
3086 : 1965273 : || GET_CODE (*recog_data.dup_loc[i]) == MULT
3087 : 1965273 : || MEM_P (*recog_data.dup_loc[i]))
3088 : 546318 : *recog_data.dup_loc[i] = walk_alter_subreg (recog_data.dup_loc[i], &changed);
3089 : : }
3090 : 96999698 : if (changed)
3091 : 176 : df_insn_rescan (insn);
3092 : 96999698 : }
3093 : :
3094 : : /* If X is a SUBREG, try to replace it with a REG or a MEM, based on
3095 : : the thing it is a subreg of. Do it anyway if FINAL_P. */
3096 : :
3097 : : rtx
3098 : 3217171 : alter_subreg (rtx *xp, bool final_p)
3099 : : {
3100 : 3217171 : rtx x = *xp;
3101 : 3217171 : rtx y = SUBREG_REG (x);
3102 : :
3103 : : /* simplify_subreg does not remove subreg from volatile references.
3104 : : We are required to. */
3105 : 3217171 : if (MEM_P (y))
3106 : : {
3107 : 221399 : poly_int64 offset = SUBREG_BYTE (x);
3108 : :
3109 : : /* For paradoxical subregs on big-endian machines, SUBREG_BYTE
3110 : : contains 0 instead of the proper offset. See simplify_subreg. */
3111 : 221399 : if (paradoxical_subreg_p (x))
3112 : 33540 : offset = byte_lowpart_offset (GET_MODE (x), GET_MODE (y));
3113 : :
3114 : 221399 : if (final_p)
3115 : 120 : *xp = adjust_address (y, GET_MODE (x), offset);
3116 : : else
3117 : 221279 : *xp = adjust_address_nv (y, GET_MODE (x), offset);
3118 : : }
3119 : 2995772 : else if (REG_P (y) && HARD_REGISTER_P (y))
3120 : : {
3121 : 5991538 : rtx new_rtx = simplify_subreg (GET_MODE (x), y, GET_MODE (y),
3122 : 2995769 : SUBREG_BYTE (x));
3123 : :
3124 : 2995769 : if (new_rtx != 0)
3125 : 2993992 : *xp = new_rtx;
3126 : 1777 : else if (final_p && REG_P (y))
3127 : : {
3128 : : /* Simplify_subreg can't handle some REG cases, but we have to. */
3129 : 1370 : unsigned int regno;
3130 : 1370 : poly_int64 offset;
3131 : :
3132 : 1370 : regno = subreg_regno (x);
3133 : 1370 : if (subreg_lowpart_p (x))
3134 : 1370 : offset = byte_lowpart_offset (GET_MODE (x), GET_MODE (y));
3135 : : else
3136 : 0 : offset = SUBREG_BYTE (x);
3137 : 1370 : *xp = gen_rtx_REG_offset (y, GET_MODE (x), regno, offset);
3138 : : }
3139 : : }
3140 : :
3141 : 3217171 : return *xp;
3142 : : }
3143 : :
3144 : : /* Do alter_subreg on all the SUBREGs contained in X. */
3145 : :
3146 : : static rtx
3147 : 159420339 : walk_alter_subreg (rtx *xp, bool *changed)
3148 : : {
3149 : 159420339 : rtx x = *xp;
3150 : 159420339 : switch (GET_CODE (x))
3151 : : {
3152 : 32857784 : case PLUS:
3153 : 32857784 : case MULT:
3154 : 32857784 : case AND:
3155 : 32857784 : case ASHIFT:
3156 : 32857784 : XEXP (x, 0) = walk_alter_subreg (&XEXP (x, 0), changed);
3157 : 32857784 : XEXP (x, 1) = walk_alter_subreg (&XEXP (x, 1), changed);
3158 : 32857784 : break;
3159 : :
3160 : 42334976 : case MEM:
3161 : 42334976 : case ZERO_EXTEND:
3162 : 42334976 : XEXP (x, 0) = walk_alter_subreg (&XEXP (x, 0), changed);
3163 : 42334976 : break;
3164 : :
3165 : 1 : case SUBREG:
3166 : 1 : *changed = true;
3167 : 1 : return alter_subreg (xp, true);
3168 : :
3169 : : default:
3170 : : break;
3171 : : }
3172 : :
3173 : 159420338 : return *xp;
3174 : : }
3175 : :
3176 : : /* Report inconsistency between the assembler template and the operands.
3177 : : In an `asm', it's the user's fault; otherwise, the compiler's fault. */
3178 : :
3179 : : void
3180 : 19 : output_operand_lossage (const char *cmsgid, ...)
3181 : : {
3182 : 19 : char *fmt_string;
3183 : 19 : char *new_message;
3184 : 19 : const char *pfx_str;
3185 : 19 : va_list ap;
3186 : :
3187 : 19 : va_start (ap, cmsgid);
3188 : :
3189 : 19 : pfx_str = this_is_asm_operands ? _("invalid 'asm': ") : "output_operand: ";
3190 : 19 : fmt_string = xasprintf ("%s%s", pfx_str, _(cmsgid));
3191 : 19 : new_message = xvasprintf (fmt_string, ap);
3192 : :
3193 : 19 : if (this_is_asm_operands)
3194 : 19 : error_for_asm (this_is_asm_operands, "%s", new_message);
3195 : : else
3196 : 0 : internal_error ("%s", new_message);
3197 : :
3198 : 19 : free (fmt_string);
3199 : 19 : free (new_message);
3200 : 19 : va_end (ap);
3201 : 19 : }
3202 : :
3203 : : /* Output of assembler code from a template, and its subroutines. */
3204 : :
3205 : : /* Annotate the assembly with a comment describing the pattern and
3206 : : alternative used. */
3207 : :
3208 : : static void
3209 : 3657 : output_asm_name (void)
3210 : : {
3211 : 3657 : if (debug_insn)
3212 : : {
3213 : 3503 : fprintf (asm_out_file, "\t%s %d\t",
3214 : 3503 : ASM_COMMENT_START, INSN_UID (debug_insn));
3215 : :
3216 : 3503 : fprintf (asm_out_file, "[c=%d",
3217 : 3503 : insn_cost (debug_insn, optimize_insn_for_speed_p ()));
3218 : 3503 : if (HAVE_ATTR_length)
3219 : 3503 : fprintf (asm_out_file, " l=%d",
3220 : : get_attr_length (debug_insn));
3221 : 3503 : fprintf (asm_out_file, "] ");
3222 : :
3223 : 3503 : int num = INSN_CODE (debug_insn);
3224 : 3503 : fprintf (asm_out_file, "%s", insn_data[num].name);
3225 : 3503 : if (insn_data[num].n_alternatives > 1)
3226 : 2024 : fprintf (asm_out_file, "/%d", which_alternative);
3227 : :
3228 : : /* Clear this so only the first assembler insn
3229 : : of any rtl insn will get the special comment for -dp. */
3230 : 3503 : debug_insn = 0;
3231 : : }
3232 : 3657 : }
3233 : :
3234 : : /* If OP is a REG or MEM and we can find a MEM_EXPR corresponding to it
3235 : : or its address, return that expr . Set *PADDRESSP to 1 if the expr
3236 : : corresponds to the address of the object and 0 if to the object. */
3237 : :
3238 : : static tree
3239 : 391 : get_mem_expr_from_op (rtx op, int *paddressp)
3240 : : {
3241 : 391 : tree expr;
3242 : 391 : int inner_addressp;
3243 : :
3244 : 391 : *paddressp = 0;
3245 : :
3246 : 391 : if (REG_P (op))
3247 : 254 : return REG_EXPR (op);
3248 : 137 : else if (!MEM_P (op))
3249 : : return 0;
3250 : :
3251 : 51 : if (MEM_EXPR (op) != 0)
3252 : : return MEM_EXPR (op);
3253 : :
3254 : : /* Otherwise we have an address, so indicate it and look at the address. */
3255 : 0 : *paddressp = 1;
3256 : 0 : op = XEXP (op, 0);
3257 : :
3258 : : /* First check if we have a decl for the address, then look at the right side
3259 : : if it is a PLUS. Otherwise, strip off arithmetic and keep looking.
3260 : : But don't allow the address to itself be indirect. */
3261 : 0 : if ((expr = get_mem_expr_from_op (op, &inner_addressp)) && ! inner_addressp)
3262 : : return expr;
3263 : 0 : else if (GET_CODE (op) == PLUS
3264 : 0 : && (expr = get_mem_expr_from_op (XEXP (op, 1), &inner_addressp)))
3265 : : return expr;
3266 : :
3267 : 0 : while (UNARY_P (op)
3268 : 0 : || GET_RTX_CLASS (GET_CODE (op)) == RTX_BIN_ARITH)
3269 : 0 : op = XEXP (op, 0);
3270 : :
3271 : 0 : expr = get_mem_expr_from_op (op, &inner_addressp);
3272 : 0 : return inner_addressp ? 0 : expr;
3273 : : }
3274 : :
3275 : : /* Output operand names for assembler instructions. OPERANDS is the
3276 : : operand vector, OPORDER is the order to write the operands, and NOPS
3277 : : is the number of operands to write. */
3278 : :
3279 : : static void
3280 : 253 : output_asm_operand_names (rtx *operands, int *oporder, int nops)
3281 : : {
3282 : 253 : int wrote = 0;
3283 : 253 : int i;
3284 : :
3285 : 644 : for (i = 0; i < nops; i++)
3286 : : {
3287 : 391 : int addressp;
3288 : 391 : rtx op = operands[oporder[i]];
3289 : 391 : tree expr = get_mem_expr_from_op (op, &addressp);
3290 : :
3291 : 614 : fprintf (asm_out_file, "%c%s",
3292 : : wrote ? ',' : '\t', wrote ? "" : ASM_COMMENT_START);
3293 : 391 : wrote = 1;
3294 : 391 : if (expr)
3295 : : {
3296 : 236 : fprintf (asm_out_file, "%s",
3297 : 236 : addressp ? "*" : "");
3298 : 236 : print_mem_expr (asm_out_file, expr);
3299 : 236 : wrote = 1;
3300 : : }
3301 : 69 : else if (REG_P (op) && ORIGINAL_REGNO (op)
3302 : 223 : && ORIGINAL_REGNO (op) != REGNO (op))
3303 : 41 : fprintf (asm_out_file, " tmp%i", ORIGINAL_REGNO (op));
3304 : : }
3305 : 253 : }
3306 : :
3307 : : #ifdef ASSEMBLER_DIALECT
3308 : : /* Helper function to parse assembler dialects in the asm string.
3309 : : This is called from output_asm_insn and asm_fprintf. */
3310 : : static const char *
3311 : 240586742 : do_assembler_dialects (const char *p, int *dialect)
3312 : : {
3313 : 240586742 : char c = *(p - 1);
3314 : :
3315 : 240586742 : switch (c)
3316 : : {
3317 : 120293370 : case '{':
3318 : 120293370 : {
3319 : 120293370 : int i;
3320 : :
3321 : 120293370 : if (*dialect)
3322 : 0 : output_operand_lossage ("nested assembly dialect alternatives");
3323 : : else
3324 : 120293370 : *dialect = 1;
3325 : :
3326 : : /* If we want the first dialect, do nothing. Otherwise, skip
3327 : : DIALECT_NUMBER of strings ending with '|'. */
3328 : 120294268 : for (i = 0; i < dialect_number; i++)
3329 : : {
3330 : 7949 : while (*p && *p != '}')
3331 : : {
3332 : 7524 : if (*p == '|')
3333 : : {
3334 : 898 : p++;
3335 : 898 : break;
3336 : : }
3337 : :
3338 : : /* Skip over any character after a percent sign. */
3339 : 6626 : if (*p == '%')
3340 : 2159 : p++;
3341 : 6626 : if (*p)
3342 : 6626 : p++;
3343 : : }
3344 : :
3345 : 1323 : if (*p == '}')
3346 : : break;
3347 : : }
3348 : :
3349 : 120293370 : if (*p == '\0')
3350 : 0 : output_operand_lossage ("unterminated assembly dialect alternative");
3351 : : }
3352 : : break;
3353 : :
3354 : 61430182 : case '|':
3355 : 61430182 : if (*dialect)
3356 : : {
3357 : : /* Skip to close brace. */
3358 : 326595998 : do
3359 : : {
3360 : 326595998 : if (*p == '\0')
3361 : : {
3362 : 0 : output_operand_lossage ("unterminated assembly dialect alternative");
3363 : 0 : break;
3364 : : }
3365 : :
3366 : : /* Skip over any character after a percent sign. */
3367 : 326595998 : if (*p == '%' && p[1])
3368 : : {
3369 : 120333897 : p += 2;
3370 : 120333897 : continue;
3371 : : }
3372 : :
3373 : 206262101 : if (*p++ == '}')
3374 : : break;
3375 : : }
3376 : : while (1);
3377 : :
3378 : 61430181 : *dialect = 0;
3379 : : }
3380 : : else
3381 : 1 : putc (c, asm_out_file);
3382 : : break;
3383 : :
3384 : 58863190 : case '}':
3385 : 58863190 : if (! *dialect)
3386 : 1 : putc (c, asm_out_file);
3387 : 58863190 : *dialect = 0;
3388 : 58863190 : break;
3389 : 0 : default:
3390 : 0 : gcc_unreachable ();
3391 : : }
3392 : :
3393 : 240586742 : return p;
3394 : : }
3395 : : #endif
3396 : :
3397 : : /* Output text from TEMPLATE to the assembler output file,
3398 : : obeying %-directions to substitute operands taken from
3399 : : the vector OPERANDS.
3400 : :
3401 : : %N (for N a digit) means print operand N in usual manner.
3402 : : %lN means require operand N to be a CODE_LABEL or LABEL_REF
3403 : : and print the label name with no punctuation.
3404 : : %cN means require operand N to be a constant
3405 : : and print the constant expression with no punctuation.
3406 : : %aN means expect operand N to be a memory address
3407 : : (not a memory reference!) and print a reference
3408 : : to that address.
3409 : : %nN means expect operand N to be a constant
3410 : : and print a constant expression for minus the value
3411 : : of the operand, with no other punctuation. */
3412 : :
3413 : : void
3414 : 100254735 : output_asm_insn (const char *templ, rtx *operands)
3415 : : {
3416 : 100254735 : const char *p;
3417 : 100254735 : int c;
3418 : : #ifdef ASSEMBLER_DIALECT
3419 : 100254735 : int dialect = 0;
3420 : : #endif
3421 : 100254735 : int oporder[MAX_RECOG_OPERANDS];
3422 : 100254735 : char opoutput[MAX_RECOG_OPERANDS];
3423 : 100254735 : int ops = 0;
3424 : :
3425 : : /* An insn may return a null string template
3426 : : in a case where no assembler code is needed. */
3427 : 100254735 : if (*templ == 0)
3428 : 12234253 : return;
3429 : :
3430 : 88020482 : memset (opoutput, 0, sizeof opoutput);
3431 : 88020482 : p = templ;
3432 : 88020482 : putc ('\t', asm_out_file);
3433 : :
3434 : : #ifdef ASM_OUTPUT_OPCODE
3435 : 95313969 : ASM_OUTPUT_OPCODE (asm_out_file, p);
3436 : : #endif
3437 : :
3438 : 1076960414 : while ((c = *p++))
3439 : 988939932 : switch (c)
3440 : : {
3441 : 37976 : case '\n':
3442 : 37976 : if (flag_verbose_asm)
3443 : 0 : output_asm_operand_names (operands, oporder, ops);
3444 : 37976 : if (flag_print_asm_name)
3445 : 74 : output_asm_name ();
3446 : :
3447 : 37976 : ops = 0;
3448 : 37976 : memset (opoutput, 0, sizeof opoutput);
3449 : :
3450 : 37976 : putc (c, asm_out_file);
3451 : : #ifdef ASM_OUTPUT_OPCODE
3452 : 110508 : while ((c = *p) == '\t')
3453 : : {
3454 : 34556 : putc (c, asm_out_file);
3455 : 34556 : p++;
3456 : : }
3457 : 37976 : ASM_OUTPUT_OPCODE (asm_out_file, p);
3458 : : #endif
3459 : : break;
3460 : :
3461 : : #ifdef ASSEMBLER_DIALECT
3462 : 240586742 : case '{':
3463 : 240586742 : case '}':
3464 : 240586742 : case '|':
3465 : 240586742 : p = do_assembler_dialects (p, &dialect);
3466 : 240586742 : break;
3467 : : #endif
3468 : :
3469 : 177516733 : case '%':
3470 : : /* %% outputs a single %. %{, %} and %| print {, } and | respectively
3471 : : if ASSEMBLER_DIALECT defined and these characters have a special
3472 : : meaning as dialect delimiters.*/
3473 : 177516733 : if (*p == '%'
3474 : : #ifdef ASSEMBLER_DIALECT
3475 : 177483063 : || *p == '{' || *p == '}' || *p == '|'
3476 : : #endif
3477 : : )
3478 : : {
3479 : 152190 : putc (*p, asm_out_file);
3480 : 152190 : p++;
3481 : : }
3482 : : /* %= outputs a number which is unique to each insn in the entire
3483 : : compilation. This is useful for making local labels that are
3484 : : referred to more than once in a given insn. */
3485 : 177364543 : else if (*p == '=')
3486 : : {
3487 : 19 : p++;
3488 : 19 : fprintf (asm_out_file, "%d", insn_counter);
3489 : : }
3490 : : /* % followed by a letter and some digits
3491 : : outputs an operand in a special way depending on the letter.
3492 : : Letters `acln' are implemented directly.
3493 : : Other letters are passed to `output_operand' so that
3494 : : the TARGET_PRINT_OPERAND hook can define them. */
3495 : 177364524 : else if (ISALPHA (*p))
3496 : : {
3497 : 47027432 : int letter = *p++;
3498 : 47027432 : unsigned long opnum;
3499 : 47027432 : char *endptr;
3500 : 47027432 : int letter2 = 0;
3501 : :
3502 : 47027432 : if (letter == 'c' && *p == 'c')
3503 : 40 : letter2 = *p++;
3504 : 47027432 : opnum = strtoul (p, &endptr, 10);
3505 : :
3506 : 47027432 : if (endptr == p)
3507 : 0 : output_operand_lossage ("operand number missing "
3508 : : "after %%-letter");
3509 : 47027432 : else if (this_is_asm_operands && opnum >= insn_noperands)
3510 : 0 : output_operand_lossage ("operand number out of range");
3511 : 47027432 : else if (letter == 'l')
3512 : 8209498 : output_asm_label (operands[opnum]);
3513 : 38817934 : else if (letter == 'a')
3514 : 2188 : output_address (VOIDmode, operands[opnum]);
3515 : 38815746 : else if (letter == 'c')
3516 : : {
3517 : 189543 : if (letter2 == 'c' || CONSTANT_ADDRESS_P (operands[opnum]))
3518 : 871 : output_addr_const (asm_out_file, operands[opnum]);
3519 : : else
3520 : 188672 : output_operand (operands[opnum], 'c');
3521 : : }
3522 : 38626203 : else if (letter == 'n')
3523 : : {
3524 : 0 : if (CONST_INT_P (operands[opnum]))
3525 : 0 : fprintf (asm_out_file, HOST_WIDE_INT_PRINT_DEC,
3526 : 0 : - INTVAL (operands[opnum]));
3527 : : else
3528 : : {
3529 : 0 : putc ('-', asm_out_file);
3530 : 0 : output_addr_const (asm_out_file, operands[opnum]);
3531 : : }
3532 : : }
3533 : : else
3534 : 38626203 : output_operand (operands[opnum], letter);
3535 : :
3536 : 47027432 : if (!opoutput[opnum])
3537 : 44771316 : oporder[ops++] = opnum;
3538 : 47027432 : opoutput[opnum] = 1;
3539 : :
3540 : 47027432 : p = endptr;
3541 : 47027432 : c = *p;
3542 : : }
3543 : : /* % followed by a digit outputs an operand the default way. */
3544 : 130337092 : else if (ISDIGIT (*p))
3545 : : {
3546 : 109888781 : unsigned long opnum;
3547 : 109888781 : char *endptr;
3548 : :
3549 : 109888781 : opnum = strtoul (p, &endptr, 10);
3550 : 109888781 : if (this_is_asm_operands && opnum >= insn_noperands)
3551 : 3 : output_operand_lossage ("operand number out of range");
3552 : : else
3553 : 109888778 : output_operand (operands[opnum], 0);
3554 : :
3555 : 109888781 : if (!opoutput[opnum])
3556 : 107633398 : oporder[ops++] = opnum;
3557 : 109888781 : opoutput[opnum] = 1;
3558 : :
3559 : 109888781 : p = endptr;
3560 : 109888781 : c = *p;
3561 : : }
3562 : : /* % followed by punctuation: output something for that
3563 : : punctuation character alone, with no operand. The
3564 : : TARGET_PRINT_OPERAND hook decides what is actually done. */
3565 : 20448311 : else if (targetm.asm_out.print_operand_punct_valid_p ((unsigned char) *p))
3566 : 20448311 : output_operand (NULL_RTX, *p++);
3567 : : else
3568 : 0 : output_operand_lossage ("invalid %%-code");
3569 : : break;
3570 : :
3571 : 570798481 : default:
3572 : 570798481 : putc (c, asm_out_file);
3573 : : }
3574 : :
3575 : : /* Try to keep the asm a bit more readable. */
3576 : 88020482 : if ((flag_verbose_asm || flag_print_asm_name) && strlen (templ) < 9)
3577 : 418 : putc ('\t', asm_out_file);
3578 : :
3579 : : /* Write out the variable names for operands, if we know them. */
3580 : 88020482 : if (flag_verbose_asm)
3581 : 253 : output_asm_operand_names (operands, oporder, ops);
3582 : 88020482 : if (flag_print_asm_name)
3583 : 3583 : output_asm_name ();
3584 : :
3585 : 88020482 : putc ('\n', asm_out_file);
3586 : : }
3587 : :
3588 : : /* Output a LABEL_REF, or a bare CODE_LABEL, as an assembler symbol. */
3589 : :
3590 : : void
3591 : 8215044 : output_asm_label (rtx x)
3592 : : {
3593 : 8215044 : char buf[256];
3594 : :
3595 : 8215044 : if (GET_CODE (x) == LABEL_REF)
3596 : 5670 : x = label_ref_label (x);
3597 : 8215044 : if (LABEL_P (x)
3598 : 90 : || (NOTE_P (x)
3599 : 90 : && NOTE_KIND (x) == NOTE_INSN_DELETED_LABEL))
3600 : 8215044 : ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
3601 : : else
3602 : 0 : output_operand_lossage ("'%%l' operand isn't a label");
3603 : :
3604 : 8215044 : assemble_name (asm_out_file, buf);
3605 : 8215044 : }
3606 : :
3607 : : /* Marks SYMBOL_REFs in x as referenced through use of assemble_external. */
3608 : :
3609 : : void
3610 : 148703653 : mark_symbol_refs_as_used (rtx x)
3611 : : {
3612 : 148703653 : subrtx_iterator::array_type array;
3613 : 404166036 : FOR_EACH_SUBRTX (iter, array, x, ALL)
3614 : : {
3615 : 255462383 : const_rtx x = *iter;
3616 : 255462383 : if (GET_CODE (x) == SYMBOL_REF)
3617 : 269678499 : if (tree t = SYMBOL_REF_DECL (x))
3618 : 14216116 : assemble_external (t);
3619 : : }
3620 : 148703653 : }
3621 : :
3622 : : /* Print operand X using machine-dependent assembler syntax.
3623 : : CODE is a non-digit that preceded the operand-number in the % spec,
3624 : : such as 'z' if the spec was `%z3'. CODE is 0 if there was no char
3625 : : between the % and the digits.
3626 : : When CODE is a non-letter, X is 0.
3627 : :
3628 : : The meanings of the letters are machine-dependent and controlled
3629 : : by TARGET_PRINT_OPERAND. */
3630 : :
3631 : : void
3632 : 169151964 : output_operand (rtx x, int code ATTRIBUTE_UNUSED)
3633 : : {
3634 : 169151964 : if (x && GET_CODE (x) == SUBREG)
3635 : 1 : x = alter_subreg (&x, true);
3636 : :
3637 : : /* X must not be a pseudo reg. */
3638 : 169151964 : if (!targetm.no_register_allocation)
3639 : 169151964 : gcc_assert (!x || !REG_P (x) || REGNO (x) < FIRST_PSEUDO_REGISTER);
3640 : :
3641 : 169151964 : targetm.asm_out.print_operand (asm_out_file, x, code);
3642 : :
3643 : 169151964 : if (x == NULL_RTX)
3644 : : return;
3645 : :
3646 : 148703653 : mark_symbol_refs_as_used (x);
3647 : : }
3648 : :
3649 : : /* Print a memory reference operand for address X using
3650 : : machine-dependent assembler syntax. */
3651 : :
3652 : : void
3653 : 3361955 : output_address (machine_mode mode, rtx x)
3654 : : {
3655 : 3361955 : bool changed = false;
3656 : 3361955 : walk_alter_subreg (&x, &changed);
3657 : 3361955 : targetm.asm_out.print_operand_address (asm_out_file, mode, x);
3658 : 3361955 : }
3659 : :
3660 : : /* Print an integer constant expression in assembler syntax.
3661 : : Addition and subtraction are the only arithmetic
3662 : : that may appear in these expressions. */
3663 : :
3664 : : void
3665 : 149053211 : output_addr_const (FILE *file, rtx x)
3666 : : {
3667 : 158852729 : char buf[256];
3668 : :
3669 : 158852729 : restart:
3670 : 158852729 : switch (GET_CODE (x))
3671 : : {
3672 : 539 : case PC:
3673 : 539 : putc ('.', file);
3674 : 539 : break;
3675 : :
3676 : 112789395 : case SYMBOL_REF:
3677 : 112789395 : if (SYMBOL_REF_DECL (x))
3678 : 19776402 : assemble_external (SYMBOL_REF_DECL (x));
3679 : : #ifdef ASM_OUTPUT_SYMBOL_REF
3680 : 112789395 : ASM_OUTPUT_SYMBOL_REF (file, x);
3681 : : #else
3682 : : assemble_name (file, XSTR (x, 0));
3683 : : #endif
3684 : : break;
3685 : :
3686 : 14984 : case LABEL_REF:
3687 : 14984 : x = label_ref_label (x);
3688 : : /* Fall through. */
3689 : 14984 : case CODE_LABEL:
3690 : 14984 : ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
3691 : : #ifdef ASM_OUTPUT_LABEL_REF
3692 : : ASM_OUTPUT_LABEL_REF (file, buf);
3693 : : #else
3694 : 14984 : assemble_name (file, buf);
3695 : : #endif
3696 : 14984 : break;
3697 : :
3698 : 36234427 : case CONST_INT:
3699 : 36234427 : fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
3700 : 36234427 : break;
3701 : :
3702 : 2603815 : case CONST:
3703 : : /* This used to output parentheses around the expression,
3704 : : but that does not work on the 386 (either ATT or BSD assembler). */
3705 : 2603815 : output_addr_const (file, XEXP (x, 0));
3706 : 2603815 : break;
3707 : :
3708 : 2 : case CONST_WIDE_INT:
3709 : : /* We do not know the mode here so we have to use a round about
3710 : : way to build a wide-int to get it printed properly. */
3711 : 2 : {
3712 : 2 : wide_int w = wide_int::from_array (&CONST_WIDE_INT_ELT (x, 0),
3713 : 2 : CONST_WIDE_INT_NUNITS (x),
3714 : 2 : CONST_WIDE_INT_NUNITS (x)
3715 : 2 : * HOST_BITS_PER_WIDE_INT,
3716 : 2 : false);
3717 : 2 : print_decs (w, file);
3718 : 2 : }
3719 : 2 : break;
3720 : :
3721 : 0 : case CONST_DOUBLE:
3722 : 0 : if (CONST_DOUBLE_AS_INT_P (x))
3723 : : {
3724 : : /* We can use %d if the number is one word and positive. */
3725 : 0 : if (CONST_DOUBLE_HIGH (x))
3726 : 0 : fprintf (file, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
3727 : : (unsigned HOST_WIDE_INT) CONST_DOUBLE_HIGH (x),
3728 : 0 : (unsigned HOST_WIDE_INT) CONST_DOUBLE_LOW (x));
3729 : 0 : else if (CONST_DOUBLE_LOW (x) < 0)
3730 : 0 : fprintf (file, HOST_WIDE_INT_PRINT_HEX,
3731 : : (unsigned HOST_WIDE_INT) CONST_DOUBLE_LOW (x));
3732 : : else
3733 : 0 : fprintf (file, HOST_WIDE_INT_PRINT_DEC, CONST_DOUBLE_LOW (x));
3734 : : }
3735 : : else
3736 : : /* We can't handle floating point constants;
3737 : : PRINT_OPERAND must handle them. */
3738 : 0 : output_operand_lossage ("floating constant misused");
3739 : : break;
3740 : :
3741 : 0 : case CONST_FIXED:
3742 : 0 : fprintf (file, HOST_WIDE_INT_PRINT_DEC, CONST_FIXED_VALUE_LOW (x));
3743 : 0 : break;
3744 : :
3745 : 2624305 : case PLUS:
3746 : : /* Some assemblers need integer constants to appear last (eg masm). */
3747 : 2624305 : if (CONST_INT_P (XEXP (x, 0)))
3748 : : {
3749 : 0 : output_addr_const (file, XEXP (x, 1));
3750 : 0 : if (INTVAL (XEXP (x, 0)) >= 0)
3751 : 0 : fprintf (file, "+");
3752 : 0 : output_addr_const (file, XEXP (x, 0));
3753 : : }
3754 : : else
3755 : : {
3756 : 2624305 : output_addr_const (file, XEXP (x, 0));
3757 : 2624305 : if (!CONST_INT_P (XEXP (x, 1))
3758 : 2624305 : || INTVAL (XEXP (x, 1)) >= 0)
3759 : 2604185 : fprintf (file, "+");
3760 : 2624305 : output_addr_const (file, XEXP (x, 1));
3761 : : }
3762 : : break;
3763 : :
3764 : 4571462 : case MINUS:
3765 : : /* Avoid outputting things like x-x or x+5-x,
3766 : : since some assemblers can't handle that. */
3767 : 4571462 : x = simplify_subtraction (x);
3768 : 4571462 : if (GET_CODE (x) != MINUS)
3769 : 0 : goto restart;
3770 : :
3771 : 4571462 : output_addr_const (file, XEXP (x, 0));
3772 : 4571462 : fprintf (file, "-");
3773 : 4571462 : if ((CONST_INT_P (XEXP (x, 1)) && INTVAL (XEXP (x, 1)) >= 0)
3774 : 4571462 : || GET_CODE (XEXP (x, 1)) == PC
3775 : 4570923 : || GET_CODE (XEXP (x, 1)) == SYMBOL_REF)
3776 : : output_addr_const (file, XEXP (x, 1));
3777 : : else
3778 : : {
3779 : 64 : fputs (targetm.asm_out.open_paren, file);
3780 : 64 : output_addr_const (file, XEXP (x, 1));
3781 : 64 : fputs (targetm.asm_out.close_paren, file);
3782 : : }
3783 : : break;
3784 : :
3785 : 0 : case ZERO_EXTEND:
3786 : 0 : case SIGN_EXTEND:
3787 : 0 : case SUBREG:
3788 : 0 : case TRUNCATE:
3789 : 0 : output_addr_const (file, XEXP (x, 0));
3790 : 0 : break;
3791 : :
3792 : 13800 : default:
3793 : 13800 : if (targetm.asm_out.output_addr_const_extra (file, x))
3794 : : break;
3795 : :
3796 : 0 : output_operand_lossage ("invalid expression as operand");
3797 : : }
3798 : 149053211 : }
3799 : :
3800 : : /* Output a quoted string. */
3801 : :
3802 : : void
3803 : 1472830 : output_quoted_string (FILE *asm_file, const char *string)
3804 : : {
3805 : : #ifdef OUTPUT_QUOTED_STRING
3806 : : OUTPUT_QUOTED_STRING (asm_file, string);
3807 : : #else
3808 : 1472830 : char c;
3809 : :
3810 : 1472830 : putc ('\"', asm_file);
3811 : 84662413 : while ((c = *string++) != 0)
3812 : : {
3813 : 81716753 : if (ISPRINT (c))
3814 : : {
3815 : 81716741 : if (c == '\"' || c == '\\')
3816 : 14 : putc ('\\', asm_file);
3817 : 81716741 : putc (c, asm_file);
3818 : : }
3819 : : else
3820 : 12 : fprintf (asm_file, "\\%03o", (unsigned char) c);
3821 : : }
3822 : 1472830 : putc ('\"', asm_file);
3823 : : #endif
3824 : 1472830 : }
3825 : :
3826 : : /* Write a HOST_WIDE_INT number in hex form 0x1234, fast. */
3827 : :
3828 : : void
3829 : 455701822 : fprint_whex (FILE *f, unsigned HOST_WIDE_INT value)
3830 : : {
3831 : 455701822 : char buf[2 + CHAR_BIT * sizeof (value) / 4];
3832 : 455701822 : if (value == 0)
3833 : 43891031 : putc ('0', f);
3834 : : else
3835 : : {
3836 : : char *p = buf + sizeof (buf);
3837 : 859866742 : do
3838 : 859866742 : *--p = "0123456789abcdef"[value % 16];
3839 : 859866742 : while ((value /= 16) != 0);
3840 : 411810791 : *--p = 'x';
3841 : 411810791 : *--p = '0';
3842 : 411810791 : fwrite (p, 1, buf + sizeof (buf) - p, f);
3843 : : }
3844 : 455701822 : }
3845 : :
3846 : : /* Internal function that prints an unsigned long in decimal in reverse.
3847 : : The output string IS NOT null-terminated. */
3848 : :
3849 : : static int
3850 : 402088608 : sprint_ul_rev (char *s, unsigned long value)
3851 : : {
3852 : 0 : int i = 0;
3853 : 1193019096 : do
3854 : : {
3855 : 1193019096 : s[i] = "0123456789"[value % 10];
3856 : 1193019096 : value /= 10;
3857 : 1193019096 : i++;
3858 : : /* alternate version, without modulo */
3859 : : /* oldval = value; */
3860 : : /* value /= 10; */
3861 : : /* s[i] = "0123456789" [oldval - 10*value]; */
3862 : : /* i++ */
3863 : : }
3864 : 1193019096 : while (value != 0);
3865 : 296700341 : return i;
3866 : : }
3867 : :
3868 : : /* Write an unsigned long as decimal to a file, fast. */
3869 : :
3870 : : void
3871 : 105388267 : fprint_ul (FILE *f, unsigned long value)
3872 : : {
3873 : : /* python says: len(str(2**64)) == 20 */
3874 : 105388267 : char s[20];
3875 : 105388267 : int i;
3876 : :
3877 : 105388267 : i = sprint_ul_rev (s, value);
3878 : :
3879 : : /* It's probably too small to bother with string reversal and fputs. */
3880 : 195795281 : do
3881 : : {
3882 : 195795281 : i--;
3883 : 195795281 : putc (s[i], f);
3884 : : }
3885 : 195795281 : while (i != 0);
3886 : 105388267 : }
3887 : :
3888 : : /* Write an unsigned long as decimal to a string, fast.
3889 : : s must be wide enough to not overflow, at least 21 chars.
3890 : : Returns the length of the string (without terminating '\0'). */
3891 : :
3892 : : int
3893 : 296700341 : sprint_ul (char *s, unsigned long value)
3894 : : {
3895 : 296700341 : int len = sprint_ul_rev (s, value);
3896 : 296700341 : s[len] = '\0';
3897 : :
3898 : 296700341 : std::reverse (s, s + len);
3899 : 296700341 : return len;
3900 : : }
3901 : :
3902 : : /* A poor man's fprintf, with the added features of %I, %R, %L, and %U.
3903 : : %R prints the value of REGISTER_PREFIX.
3904 : : %L prints the value of LOCAL_LABEL_PREFIX.
3905 : : %U prints the value of USER_LABEL_PREFIX.
3906 : : %I prints the value of IMMEDIATE_PREFIX.
3907 : : %O runs ASM_OUTPUT_OPCODE to transform what follows in the string.
3908 : : Also supported are %d, %i, %u, %x, %X, %o, %c, %s and %%.
3909 : :
3910 : : We handle alternate assembler dialects here, just like output_asm_insn. */
3911 : :
3912 : : void
3913 : 2 : asm_fprintf (FILE *file, const char *p, ...)
3914 : : {
3915 : 2 : char buf[10];
3916 : 2 : char *q, c;
3917 : : #ifdef ASSEMBLER_DIALECT
3918 : 2 : int dialect = 0;
3919 : : #endif
3920 : 2 : va_list argptr;
3921 : :
3922 : 2 : va_start (argptr, p);
3923 : :
3924 : 2 : buf[0] = '%';
3925 : :
3926 : 21 : while ((c = *p++))
3927 : 19 : switch (c)
3928 : : {
3929 : : #ifdef ASSEMBLER_DIALECT
3930 : 0 : case '{':
3931 : 0 : case '}':
3932 : 0 : case '|':
3933 : 0 : p = do_assembler_dialects (p, &dialect);
3934 : 0 : break;
3935 : : #endif
3936 : :
3937 : 6 : case '%':
3938 : 6 : c = *p++;
3939 : 6 : q = &buf[1];
3940 : 6 : while (strchr ("-+ #0", c))
3941 : : {
3942 : 0 : *q++ = c;
3943 : 0 : c = *p++;
3944 : : }
3945 : 6 : while (ISDIGIT (c) || c == '.')
3946 : : {
3947 : 0 : *q++ = c;
3948 : 0 : c = *p++;
3949 : : }
3950 : 6 : switch (c)
3951 : : {
3952 : 2 : case '%':
3953 : 2 : putc ('%', file);
3954 : 2 : break;
3955 : :
3956 : 0 : case 'd': case 'i': case 'u':
3957 : 0 : case 'x': case 'X': case 'o':
3958 : 0 : case 'c':
3959 : 0 : *q++ = c;
3960 : 0 : *q = 0;
3961 : 0 : fprintf (file, buf, va_arg (argptr, int));
3962 : 0 : break;
3963 : :
3964 : 0 : case 'w':
3965 : : /* This is a prefix to the 'd', 'i', 'u', 'x', 'X', and
3966 : : 'o' cases, but we do not check for those cases. It
3967 : : means that the value is a HOST_WIDE_INT, which may be
3968 : : either `long' or `long long'. */
3969 : 0 : memcpy (q, HOST_WIDE_INT_PRINT, strlen (HOST_WIDE_INT_PRINT));
3970 : 0 : q += strlen (HOST_WIDE_INT_PRINT);
3971 : 0 : *q++ = *p++;
3972 : 0 : *q = 0;
3973 : 0 : fprintf (file, buf, va_arg (argptr, HOST_WIDE_INT));
3974 : 0 : break;
3975 : :
3976 : 0 : case 'l':
3977 : 0 : *q++ = c;
3978 : : #ifdef HAVE_LONG_LONG
3979 : 0 : if (*p == 'l')
3980 : : {
3981 : 0 : *q++ = *p++;
3982 : 0 : *q++ = *p++;
3983 : 0 : *q = 0;
3984 : 0 : fprintf (file, buf, va_arg (argptr, long long));
3985 : : }
3986 : : else
3987 : : #endif
3988 : : {
3989 : 0 : *q++ = *p++;
3990 : 0 : *q = 0;
3991 : 0 : fprintf (file, buf, va_arg (argptr, long));
3992 : : }
3993 : :
3994 : : break;
3995 : :
3996 : 0 : case 's':
3997 : 0 : *q++ = c;
3998 : 0 : *q = 0;
3999 : 0 : fprintf (file, buf, va_arg (argptr, char *));
4000 : 0 : break;
4001 : :
4002 : 0 : case 'O':
4003 : : #ifdef ASM_OUTPUT_OPCODE
4004 : 0 : ASM_OUTPUT_OPCODE (asm_out_file, p);
4005 : : #endif
4006 : : break;
4007 : :
4008 : : case 'R':
4009 : : #ifdef REGISTER_PREFIX
4010 : : fprintf (file, "%s", REGISTER_PREFIX);
4011 : : #endif
4012 : : break;
4013 : :
4014 : : case 'I':
4015 : : #ifdef IMMEDIATE_PREFIX
4016 : : fprintf (file, "%s", IMMEDIATE_PREFIX);
4017 : : #endif
4018 : : break;
4019 : :
4020 : 0 : case 'L':
4021 : : #ifdef LOCAL_LABEL_PREFIX
4022 : 0 : fprintf (file, "%s", LOCAL_LABEL_PREFIX);
4023 : : #endif
4024 : 0 : break;
4025 : :
4026 : 0 : case 'U':
4027 : 0 : fputs (user_label_prefix, file);
4028 : 0 : break;
4029 : :
4030 : : #ifdef ASM_FPRINTF_EXTENSIONS
4031 : : /* Uppercase letters are reserved for general use by asm_fprintf
4032 : : and so are not available to target specific code. In order to
4033 : : prevent the ASM_FPRINTF_EXTENSIONS macro from using them then,
4034 : : they are defined here. As they get turned into real extensions
4035 : : to asm_fprintf they should be removed from this list. */
4036 : : case 'A': case 'B': case 'C': case 'D': case 'E':
4037 : : case 'F': case 'G': case 'H': case 'J': case 'K':
4038 : : case 'M': case 'N': case 'P': case 'Q': case 'S':
4039 : : case 'T': case 'V': case 'W': case 'Y': case 'Z':
4040 : : break;
4041 : :
4042 : 4 : ASM_FPRINTF_EXTENSIONS (file, argptr, p)
4043 : : #endif
4044 : 0 : default:
4045 : 0 : gcc_unreachable ();
4046 : : }
4047 : : break;
4048 : :
4049 : 13 : default:
4050 : 13 : putc (c, file);
4051 : : }
4052 : 2 : va_end (argptr);
4053 : 2 : }
4054 : :
4055 : : /* Return true if this function has no function calls. */
4056 : :
4057 : : bool
4058 : 2899894 : leaf_function_p (void)
4059 : : {
4060 : 2899894 : rtx_insn *insn;
4061 : :
4062 : : /* Ensure we walk the entire function body. */
4063 : 2899894 : gcc_assert (!in_sequence_p ());
4064 : :
4065 : : /* Some back-ends (e.g. s390) want leaf functions to stay leaf
4066 : : functions even if they call mcount. */
4067 : 2899894 : if (crtl->profile && !targetm.keep_leaf_when_profiled ())
4068 : : return false;
4069 : :
4070 : 73516821 : for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
4071 : : {
4072 : 72466592 : if (CALL_P (insn)
4073 : 1980437 : && ! SIBLING_CALL_P (insn)
4074 : 74315667 : && ! FAKE_CALL_P (insn))
4075 : : return false;
4076 : 70617617 : if (NONJUMP_INSN_P (insn)
4077 : 34897656 : && GET_CODE (PATTERN (insn)) == SEQUENCE
4078 : 0 : && CALL_P (XVECEXP (PATTERN (insn), 0, 0))
4079 : 70617617 : && ! SIBLING_CALL_P (XVECEXP (PATTERN (insn), 0, 0)))
4080 : : return false;
4081 : : }
4082 : :
4083 : : return true;
4084 : : }
4085 : :
4086 : : /* Return true if branch is a forward branch.
4087 : : Uses insn_shuid array, so it works only in the final pass. May be used by
4088 : : output templates to customary add branch prediction hints.
4089 : : */
4090 : : bool
4091 : 0 : final_forward_branch_p (rtx_insn *insn)
4092 : : {
4093 : 0 : int insn_id, label_id;
4094 : :
4095 : 0 : gcc_assert (uid_shuid);
4096 : 0 : insn_id = INSN_SHUID (insn);
4097 : 0 : label_id = INSN_SHUID (JUMP_LABEL (insn));
4098 : : /* We've hit some insns that does not have id information available. */
4099 : 0 : gcc_assert (insn_id && label_id);
4100 : 0 : return insn_id < label_id;
4101 : : }
4102 : :
4103 : : /* On some machines, a function with no call insns
4104 : : can run faster if it doesn't create its own register window.
4105 : : When output, the leaf function should use only the "output"
4106 : : registers. Ordinarily, the function would be compiled to use
4107 : : the "input" registers to find its arguments; it is a candidate
4108 : : for leaf treatment if it uses only the "input" registers.
4109 : : Leaf function treatment means renumbering so the function
4110 : : uses the "output" registers instead. */
4111 : :
4112 : : #ifdef LEAF_REGISTERS
4113 : :
4114 : : /* Return bool if this function uses only the registers that can be
4115 : : safely renumbered. */
4116 : :
4117 : : bool
4118 : : only_leaf_regs_used (void)
4119 : : {
4120 : : int i;
4121 : : const char *const permitted_reg_in_leaf_functions = LEAF_REGISTERS;
4122 : :
4123 : : for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
4124 : : if ((df_regs_ever_live_p (i) || global_regs[i])
4125 : : && ! permitted_reg_in_leaf_functions[i])
4126 : : return false;
4127 : :
4128 : : if (crtl->uses_pic_offset_table
4129 : : && pic_offset_table_rtx != 0
4130 : : && REG_P (pic_offset_table_rtx)
4131 : : && ! permitted_reg_in_leaf_functions[REGNO (pic_offset_table_rtx)])
4132 : : return false;
4133 : :
4134 : : return true;
4135 : : }
4136 : :
4137 : : /* Scan all instructions and renumber all registers into those
4138 : : available in leaf functions. */
4139 : :
4140 : : static void
4141 : : leaf_renumber_regs (rtx_insn *first)
4142 : : {
4143 : : rtx_insn *insn;
4144 : :
4145 : : /* Renumber only the actual patterns.
4146 : : The reg-notes can contain frame pointer refs,
4147 : : and renumbering them could crash, and should not be needed. */
4148 : : for (insn = first; insn; insn = NEXT_INSN (insn))
4149 : : if (INSN_P (insn))
4150 : : leaf_renumber_regs_insn (PATTERN (insn));
4151 : : }
4152 : :
4153 : : /* Scan IN_RTX and its subexpressions, and renumber all regs into those
4154 : : available in leaf functions. */
4155 : :
4156 : : void
4157 : : leaf_renumber_regs_insn (rtx in_rtx)
4158 : : {
4159 : : int i, j;
4160 : : const char *format_ptr;
4161 : :
4162 : : if (in_rtx == 0)
4163 : : return;
4164 : :
4165 : : /* Renumber all input-registers into output-registers.
4166 : : renumbered_regs would be 1 for an output-register;
4167 : : they */
4168 : :
4169 : : if (REG_P (in_rtx))
4170 : : {
4171 : : int newreg;
4172 : :
4173 : : /* Don't renumber the same reg twice. */
4174 : : if (in_rtx->used)
4175 : : return;
4176 : :
4177 : : newreg = REGNO (in_rtx);
4178 : : /* Don't try to renumber pseudo regs. It is possible for a pseudo reg
4179 : : to reach here as part of a REG_NOTE. */
4180 : : if (newreg >= FIRST_PSEUDO_REGISTER)
4181 : : {
4182 : : in_rtx->used = 1;
4183 : : return;
4184 : : }
4185 : : newreg = LEAF_REG_REMAP (newreg);
4186 : : gcc_assert (newreg >= 0);
4187 : : df_set_regs_ever_live (REGNO (in_rtx), false);
4188 : : df_set_regs_ever_live (newreg, true);
4189 : : SET_REGNO (in_rtx, newreg);
4190 : : in_rtx->used = 1;
4191 : : return;
4192 : : }
4193 : :
4194 : : if (INSN_P (in_rtx))
4195 : : {
4196 : : /* Inside a SEQUENCE, we find insns.
4197 : : Renumber just the patterns of these insns,
4198 : : just as we do for the top-level insns. */
4199 : : leaf_renumber_regs_insn (PATTERN (in_rtx));
4200 : : return;
4201 : : }
4202 : :
4203 : : format_ptr = GET_RTX_FORMAT (GET_CODE (in_rtx));
4204 : :
4205 : : for (i = 0; i < GET_RTX_LENGTH (GET_CODE (in_rtx)); i++)
4206 : : switch (*format_ptr++)
4207 : : {
4208 : : case 'e':
4209 : : leaf_renumber_regs_insn (XEXP (in_rtx, i));
4210 : : break;
4211 : :
4212 : : case 'E':
4213 : : if (XVEC (in_rtx, i) != NULL)
4214 : : for (j = 0; j < XVECLEN (in_rtx, i); j++)
4215 : : leaf_renumber_regs_insn (XVECEXP (in_rtx, i, j));
4216 : : break;
4217 : :
4218 : : case 'S':
4219 : : case 's':
4220 : : case '0':
4221 : : case 'i':
4222 : : case 'L':
4223 : : case 'w':
4224 : : case 'p':
4225 : : case 'n':
4226 : : case 'u':
4227 : : break;
4228 : :
4229 : : default:
4230 : : gcc_unreachable ();
4231 : : }
4232 : : }
4233 : : #endif
4234 : :
4235 : : /* Turn the RTL into assembly. */
4236 : : static unsigned int
4237 : 1435843 : rest_of_handle_final (void)
4238 : : {
4239 : 1435843 : const char *fnname = get_fnname_from_decl (current_function_decl);
4240 : :
4241 : : /* Turn debug markers into notes if the var-tracking pass has not
4242 : : been invoked. */
4243 : 1435843 : if (!flag_var_tracking && MAY_HAVE_DEBUG_MARKER_INSNS)
4244 : 1 : delete_vta_debug_insns (false);
4245 : :
4246 : 1435843 : assemble_start_function (current_function_decl, fnname);
4247 : 1435843 : rtx_insn *first = get_insns ();
4248 : 1435843 : int seen = 0;
4249 : 1435843 : final_start_function_1 (&first, asm_out_file, &seen, optimize);
4250 : 1435843 : final_1 (first, asm_out_file, seen, optimize);
4251 : 1435843 : if (flag_ipa_ra
4252 : 928366 : && !lookup_attribute ("noipa", DECL_ATTRIBUTES (current_function_decl))
4253 : : /* Functions with naked attributes are supported only with basic asm
4254 : : statements in the body, thus for supported use cases the information
4255 : : on clobbered registers is not available. */
4256 : 2347856 : && !lookup_attribute ("naked", DECL_ATTRIBUTES (current_function_decl)))
4257 : 912013 : collect_fn_hard_reg_usage ();
4258 : 1435843 : final_end_function ();
4259 : :
4260 : : /* The IA-64 ".handlerdata" directive must be issued before the ".endp"
4261 : : directive that closes the procedure descriptor. Similarly, for x64 SEH.
4262 : : Otherwise it's not strictly necessary, but it doesn't hurt either. */
4263 : 2809817 : output_function_exception_table (crtl->has_bb_partition ? 1 : 0);
4264 : :
4265 : 1435843 : assemble_end_function (current_function_decl, fnname);
4266 : :
4267 : : /* Free up reg info memory. */
4268 : 1435843 : free_reg_info ();
4269 : :
4270 : 1435843 : if (! quiet_flag)
4271 : 0 : fflush (asm_out_file);
4272 : :
4273 : : /* Note that for those inline functions where we don't initially
4274 : : know for certain that we will be generating an out-of-line copy,
4275 : : the first invocation of this routine (rest_of_compilation) will
4276 : : skip over this code by doing a `goto exit_rest_of_compilation;'.
4277 : : Later on, wrapup_global_declarations will (indirectly) call
4278 : : rest_of_compilation again for those inline functions that need
4279 : : to have out-of-line copies generated. During that call, we
4280 : : *will* be routed past here. */
4281 : :
4282 : 1435843 : timevar_push (TV_SYMOUT);
4283 : 1435843 : if (!DECL_IGNORED_P (current_function_decl))
4284 : 1412566 : debug_hooks->function_decl (current_function_decl);
4285 : 1435843 : timevar_pop (TV_SYMOUT);
4286 : :
4287 : : /* Release the blocks that are linked to DECL_INITIAL() to free the memory. */
4288 : 1435843 : DECL_INITIAL (current_function_decl) = error_mark_node;
4289 : :
4290 : 1435843 : if (DECL_STATIC_CONSTRUCTOR (current_function_decl)
4291 : 1435843 : && targetm.have_ctors_dtors)
4292 : 22267 : targetm.asm_out.constructor (XEXP (DECL_RTL (current_function_decl), 0),
4293 : : decl_init_priority_lookup
4294 : 22267 : (current_function_decl));
4295 : 1435843 : if (DECL_STATIC_DESTRUCTOR (current_function_decl)
4296 : 1435843 : && targetm.have_ctors_dtors)
4297 : 1515 : targetm.asm_out.destructor (XEXP (DECL_RTL (current_function_decl), 0),
4298 : : decl_fini_priority_lookup
4299 : 1515 : (current_function_decl));
4300 : 1435843 : return 0;
4301 : : }
4302 : :
4303 : : namespace {
4304 : :
4305 : : const pass_data pass_data_final =
4306 : : {
4307 : : RTL_PASS, /* type */
4308 : : "final", /* name */
4309 : : OPTGROUP_NONE, /* optinfo_flags */
4310 : : TV_FINAL, /* tv_id */
4311 : : 0, /* properties_required */
4312 : : 0, /* properties_provided */
4313 : : 0, /* properties_destroyed */
4314 : : 0, /* todo_flags_start */
4315 : : 0, /* todo_flags_finish */
4316 : : };
4317 : :
4318 : : class pass_final : public rtl_opt_pass
4319 : : {
4320 : : public:
4321 : 283157 : pass_final (gcc::context *ctxt)
4322 : 566314 : : rtl_opt_pass (pass_data_final, ctxt)
4323 : : {}
4324 : :
4325 : : /* opt_pass methods: */
4326 : 1435843 : unsigned int execute (function *) final override
4327 : : {
4328 : 1435843 : return rest_of_handle_final ();
4329 : : }
4330 : :
4331 : : }; // class pass_final
4332 : :
4333 : : } // anon namespace
4334 : :
4335 : : rtl_opt_pass *
4336 : 283157 : make_pass_final (gcc::context *ctxt)
4337 : : {
4338 : 283157 : return new pass_final (ctxt);
4339 : : }
4340 : :
4341 : :
4342 : : static unsigned int
4343 : 1435842 : rest_of_handle_shorten_branches (void)
4344 : : {
4345 : : /* Shorten branches. */
4346 : 0 : shorten_branches (get_insns ());
4347 : 1435842 : return 0;
4348 : : }
4349 : :
4350 : : namespace {
4351 : :
4352 : : const pass_data pass_data_shorten_branches =
4353 : : {
4354 : : RTL_PASS, /* type */
4355 : : "shorten", /* name */
4356 : : OPTGROUP_NONE, /* optinfo_flags */
4357 : : TV_SHORTEN_BRANCH, /* tv_id */
4358 : : 0, /* properties_required */
4359 : : 0, /* properties_provided */
4360 : : 0, /* properties_destroyed */
4361 : : 0, /* todo_flags_start */
4362 : : 0, /* todo_flags_finish */
4363 : : };
4364 : :
4365 : : class pass_shorten_branches : public rtl_opt_pass
4366 : : {
4367 : : public:
4368 : 283157 : pass_shorten_branches (gcc::context *ctxt)
4369 : 566314 : : rtl_opt_pass (pass_data_shorten_branches, ctxt)
4370 : : {}
4371 : :
4372 : : /* opt_pass methods: */
4373 : 1435842 : unsigned int execute (function *) final override
4374 : : {
4375 : 1435842 : return rest_of_handle_shorten_branches ();
4376 : : }
4377 : :
4378 : : }; // class pass_shorten_branches
4379 : :
4380 : : } // anon namespace
4381 : :
4382 : : rtl_opt_pass *
4383 : 283157 : make_pass_shorten_branches (gcc::context *ctxt)
4384 : : {
4385 : 283157 : return new pass_shorten_branches (ctxt);
4386 : : }
4387 : :
4388 : :
4389 : : static unsigned int
4390 : 1436635 : rest_of_clean_state (void)
4391 : : {
4392 : 1436635 : rtx_insn *insn, *next;
4393 : 1436635 : FILE *final_output = NULL;
4394 : 1436635 : int save_unnumbered = flag_dump_unnumbered;
4395 : 1436635 : int save_noaddr = flag_dump_noaddr;
4396 : :
4397 : 1436635 : if (flag_dump_final_insns)
4398 : : {
4399 : 3996 : final_output = fopen (flag_dump_final_insns, "a");
4400 : 3996 : if (!final_output)
4401 : : {
4402 : 0 : error ("could not open final insn dump file %qs: %m",
4403 : : flag_dump_final_insns);
4404 : 0 : flag_dump_final_insns = NULL;
4405 : : }
4406 : : else
4407 : : {
4408 : 3996 : flag_dump_noaddr = flag_dump_unnumbered = 1;
4409 : 3996 : if (flag_compare_debug_opt || flag_compare_debug)
4410 : 3921 : dump_flags |= TDF_NOUID | TDF_COMPARE_DEBUG;
4411 : 3996 : dump_function_header (final_output, current_function_decl,
4412 : : dump_flags);
4413 : 3996 : final_insns_dump_p = true;
4414 : :
4415 : 150418 : for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
4416 : 146422 : if (LABEL_P (insn))
4417 : 4945 : INSN_UID (insn) = CODE_LABEL_NUMBER (insn);
4418 : : else
4419 : : {
4420 : 141477 : if (NOTE_P (insn))
4421 : 67390 : set_block_for_insn (insn, NULL);
4422 : 141477 : INSN_UID (insn) = 0;
4423 : : }
4424 : : }
4425 : : }
4426 : :
4427 : : /* It is very important to decompose the RTL instruction chain here:
4428 : : debug information keeps pointing into CODE_LABEL insns inside the function
4429 : : body. If these remain pointing to the other insns, we end up preserving
4430 : : whole RTL chain and attached detailed debug info in memory. */
4431 : 231522997 : for (insn = get_insns (); insn; insn = next)
4432 : : {
4433 : 230086362 : next = NEXT_INSN (insn);
4434 : 230086362 : SET_NEXT_INSN (insn) = NULL;
4435 : 230086362 : SET_PREV_INSN (insn) = NULL;
4436 : :
4437 : 230086362 : rtx_insn *call_insn = insn;
4438 : 230086362 : if (NONJUMP_INSN_P (call_insn)
4439 : 230086362 : && GET_CODE (PATTERN (call_insn)) == SEQUENCE)
4440 : : {
4441 : 0 : rtx_sequence *seq = as_a <rtx_sequence *> (PATTERN (call_insn));
4442 : 0 : call_insn = seq->insn (0);
4443 : : }
4444 : 230086362 : if (CALL_P (call_insn))
4445 : : {
4446 : 5908877 : rtx note
4447 : 5908877 : = find_reg_note (call_insn, REG_CALL_ARG_LOCATION, NULL_RTX);
4448 : 5908877 : if (note)
4449 : 3036928 : remove_note (call_insn, note);
4450 : : }
4451 : :
4452 : 230086362 : if (final_output
4453 : 146422 : && (!NOTE_P (insn)
4454 : 67390 : || (NOTE_KIND (insn) != NOTE_INSN_VAR_LOCATION
4455 : : && NOTE_KIND (insn) != NOTE_INSN_BEGIN_STMT
4456 : 67390 : && NOTE_KIND (insn) != NOTE_INSN_INLINE_ENTRY
4457 : : && NOTE_KIND (insn) != NOTE_INSN_BLOCK_BEG
4458 : : && NOTE_KIND (insn) != NOTE_INSN_BLOCK_END
4459 : : && NOTE_KIND (insn) != NOTE_INSN_DELETED_DEBUG_LABEL)))
4460 : 118529 : print_rtl_single (final_output, insn);
4461 : : }
4462 : :
4463 : 1436635 : if (final_output)
4464 : : {
4465 : 3996 : flag_dump_noaddr = save_noaddr;
4466 : 3996 : flag_dump_unnumbered = save_unnumbered;
4467 : 3996 : final_insns_dump_p = false;
4468 : :
4469 : 3996 : if (fclose (final_output))
4470 : : {
4471 : 0 : error ("could not close final insn dump file %qs: %m",
4472 : : flag_dump_final_insns);
4473 : 0 : flag_dump_final_insns = NULL;
4474 : : }
4475 : : }
4476 : :
4477 : 1436635 : flag_rerun_cse_after_global_opts = 0;
4478 : 1436635 : reload_completed = 0;
4479 : 1436635 : epilogue_completed = 0;
4480 : : #ifdef STACK_REGS
4481 : 1436635 : regstack_completed = 0;
4482 : : #endif
4483 : :
4484 : : /* Clear out the insn_length contents now that they are no
4485 : : longer valid. */
4486 : 1436635 : init_insn_lengths ();
4487 : :
4488 : : /* Show no temporary slots allocated. */
4489 : 1436635 : init_temp_slots ();
4490 : :
4491 : 1436635 : free_bb_for_insn ();
4492 : :
4493 : 1436635 : if (cfun->gimple_df)
4494 : 1436605 : delete_tree_ssa (cfun);
4495 : :
4496 : : /* We can reduce stack alignment on call site only when we are sure that
4497 : : the function body just produced will be actually used in the final
4498 : : executable. */
4499 : 1436635 : if (flag_ipa_stack_alignment
4500 : 1436635 : && decl_binds_to_current_def_p (current_function_decl))
4501 : : {
4502 : 1202698 : unsigned int pref = crtl->preferred_stack_boundary;
4503 : 1202698 : if (crtl->stack_alignment_needed > crtl->preferred_stack_boundary)
4504 : : pref = crtl->stack_alignment_needed;
4505 : 1202698 : cgraph_node::rtl_info (current_function_decl)
4506 : 1202698 : ->preferred_incoming_stack_boundary = pref;
4507 : : }
4508 : :
4509 : : /* Make sure volatile mem refs aren't considered valid operands for
4510 : : arithmetic insns. We must call this here if this is a nested inline
4511 : : function, since the above code leaves us in the init_recog state,
4512 : : and the function context push/pop code does not save/restore volatile_ok.
4513 : :
4514 : : ??? Maybe it isn't necessary for expand_start_function to call this
4515 : : anymore if we do it here? */
4516 : :
4517 : 1436635 : init_recog_no_volatile ();
4518 : :
4519 : : /* We're done with this function. Free up memory if we can. */
4520 : 1436635 : free_after_parsing (cfun);
4521 : 1436635 : free_after_compilation (cfun);
4522 : 1436635 : return 0;
4523 : : }
4524 : :
4525 : : namespace {
4526 : :
4527 : : const pass_data pass_data_clean_state =
4528 : : {
4529 : : RTL_PASS, /* type */
4530 : : "*clean_state", /* name */
4531 : : OPTGROUP_NONE, /* optinfo_flags */
4532 : : TV_FINAL, /* tv_id */
4533 : : 0, /* properties_required */
4534 : : 0, /* properties_provided */
4535 : : PROP_rtl, /* properties_destroyed */
4536 : : 0, /* todo_flags_start */
4537 : : 0, /* todo_flags_finish */
4538 : : };
4539 : :
4540 : : class pass_clean_state : public rtl_opt_pass
4541 : : {
4542 : : public:
4543 : 283157 : pass_clean_state (gcc::context *ctxt)
4544 : 566314 : : rtl_opt_pass (pass_data_clean_state, ctxt)
4545 : : {}
4546 : :
4547 : : /* opt_pass methods: */
4548 : 1436635 : unsigned int execute (function *) final override
4549 : : {
4550 : 1436635 : return rest_of_clean_state ();
4551 : : }
4552 : :
4553 : : }; // class pass_clean_state
4554 : :
4555 : : } // anon namespace
4556 : :
4557 : : rtl_opt_pass *
4558 : 283157 : make_pass_clean_state (gcc::context *ctxt)
4559 : : {
4560 : 283157 : return new pass_clean_state (ctxt);
4561 : : }
4562 : :
4563 : : /* Return true if INSN is a call to the current function. */
4564 : :
4565 : : static bool
4566 : 790949 : self_recursive_call_p (rtx_insn *insn)
4567 : : {
4568 : 790949 : tree fndecl = get_call_fndecl (insn);
4569 : 790949 : return (fndecl == current_function_decl
4570 : 790949 : && decl_binds_to_current_def_p (fndecl));
4571 : : }
4572 : :
4573 : : /* Collect hard register usage for the current function. */
4574 : :
4575 : : static void
4576 : 912013 : collect_fn_hard_reg_usage (void)
4577 : : {
4578 : 912013 : rtx_insn *insn;
4579 : : #ifdef STACK_REGS
4580 : 912013 : int i;
4581 : : #endif
4582 : 912013 : struct cgraph_rtl_info *node;
4583 : 912013 : HARD_REG_SET function_used_regs;
4584 : :
4585 : : /* ??? To be removed when all the ports have been fixed. */
4586 : 912013 : if (!targetm.call_fusage_contains_non_callee_clobbers)
4587 : 619083 : return;
4588 : :
4589 : : /* Be conservative - mark fixed and global registers as used. */
4590 : 912013 : function_used_regs = fixed_reg_set;
4591 : :
4592 : : #ifdef STACK_REGS
4593 : : /* Handle STACK_REGS conservatively, since the df-framework does not
4594 : : provide accurate information for them. */
4595 : :
4596 : 8208117 : for (i = FIRST_STACK_REG; i <= LAST_STACK_REG; i++)
4597 : 7296104 : SET_HARD_REG_BIT (function_used_regs, i);
4598 : : #endif
4599 : :
4600 : 45562688 : for (insn = get_insns (); insn != NULL_RTX; insn = next_insn (insn))
4601 : : {
4602 : 45269758 : HARD_REG_SET insn_used_regs;
4603 : :
4604 : 45269758 : if (!NONDEBUG_INSN_P (insn))
4605 : 28674506 : continue;
4606 : :
4607 : 16595252 : if (CALL_P (insn)
4608 : 16595252 : && !self_recursive_call_p (insn))
4609 : 787694 : function_used_regs
4610 : 1575388 : |= insn_callee_abi (insn).full_and_partial_reg_clobbers ();
4611 : :
4612 : 16595252 : find_all_hard_reg_sets (insn, &insn_used_regs, false);
4613 : 16595252 : function_used_regs |= insn_used_regs;
4614 : :
4615 : 33190504 : if (hard_reg_set_subset_p (crtl->abi->full_and_partial_reg_clobbers (),
4616 : : function_used_regs))
4617 : 619083 : return;
4618 : : }
4619 : :
4620 : : /* Mask out fully-saved registers, so that they don't affect equality
4621 : : comparisons between function_abis. */
4622 : 292930 : function_used_regs &= crtl->abi->full_and_partial_reg_clobbers ();
4623 : :
4624 : 292930 : node = cgraph_node::rtl_info (current_function_decl);
4625 : 292930 : gcc_assert (node != NULL);
4626 : :
4627 : 292930 : node->function_used_regs = function_used_regs;
4628 : : }
|