Line data Source code
1 : /* IRA processing allocno lives to build allocno live ranges.
2 : Copyright (C) 2006-2026 Free Software Foundation, Inc.
3 : Contributed by Vladimir Makarov <vmakarov@redhat.com>.
4 :
5 : This file is part of GCC.
6 :
7 : GCC is free software; you can redistribute it and/or modify it under
8 : the terms of the GNU General Public License as published by the Free
9 : Software Foundation; either version 3, or (at your option) any later
10 : version.
11 :
12 : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 : WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 : FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 : for more details.
16 :
17 : You should have received a copy of the GNU General Public License
18 : along with GCC; see the file COPYING3. If not see
19 : <http://www.gnu.org/licenses/>. */
20 :
21 : #include "config.h"
22 : #include "system.h"
23 : #include "coretypes.h"
24 : #include "backend.h"
25 : #include "target.h"
26 : #include "rtl.h"
27 : #include "stmt.h"
28 : #include "predict.h"
29 : #include "df.h"
30 : #include "memmodel.h"
31 : #include "tm_p.h"
32 : #include "insn-config.h"
33 : #include "regs.h"
34 : #include "ira.h"
35 : #include "ira-int.h"
36 : #include "sparseset.h"
37 : #include "function-abi.h"
38 : #include "except.h"
39 :
40 : /* The code in this file is similar to one in global but the code
41 : works on the allocno basis and creates live ranges instead of
42 : pseudo-register conflicts. */
43 :
44 : /* Program points are enumerated by numbers from range
45 : 0..IRA_MAX_POINT-1. There are approximately two times more program
46 : points than insns. Program points are places in the program where
47 : liveness info can be changed. In most general case (there are more
48 : complicated cases too) some program points correspond to places
49 : where input operand dies and other ones correspond to places where
50 : output operands are born. */
51 : int ira_max_point;
52 :
53 : /* Arrays of size IRA_MAX_POINT mapping a program point to the allocno
54 : live ranges with given start/finish point. */
55 : live_range_t *ira_start_point_ranges, *ira_finish_point_ranges;
56 :
57 : /* Number of the current program point. */
58 : static int curr_point;
59 :
60 : /* Point where register pressure excess started or -1 if there is no
61 : register pressure excess. Excess pressure for a register class at
62 : some point means that there are more allocnos of given register
63 : class living at the point than number of hard-registers of the
64 : class available for the allocation. It is defined only for
65 : pressure classes. */
66 : static int high_pressure_start_point[N_REG_CLASSES];
67 :
68 : /* Objects live at current point in the scan. */
69 : static sparseset objects_live;
70 :
71 : /* A temporary bitmap used in functions that wish to avoid visiting an allocno
72 : multiple times. */
73 : static sparseset allocnos_processed;
74 :
75 : /* Set of hard regs (except eliminable ones) currently live. */
76 : static HARD_REG_SET hard_regs_live;
77 :
78 : /* The loop tree node corresponding to the current basic block. */
79 : static ira_loop_tree_node_t curr_bb_node;
80 :
81 : /* The number of the last processed call. */
82 : static int last_call_num;
83 : /* The number of last call at which given allocno was saved. */
84 : static int *allocno_saved_at_call;
85 :
86 : /* The value returned by ira_setup_alts for the current instruction;
87 : i.e. the set of alternatives that we should consider to be likely
88 : candidates during reloading. */
89 : static alternative_mask preferred_alternatives;
90 :
91 : /* If non-NULL, the source operand of a register to register copy for which
92 : we should not add a conflict with the copy's destination operand. */
93 : static rtx ignore_reg_for_conflicts;
94 :
95 : /* Record hard register REGNO as now being live. */
96 : static void
97 36828982 : make_hard_regno_live (int regno)
98 : {
99 36828982 : SET_HARD_REG_BIT (hard_regs_live, regno);
100 34640424 : }
101 :
102 : /* Process the definition of hard register REGNO. This updates
103 : hard_regs_live and hard reg conflict information for living allocnos. */
104 : static void
105 15021498 : make_hard_regno_dead (int regno)
106 : {
107 15021498 : unsigned int i;
108 279346079 : EXECUTE_IF_SET_IN_SPARSESET (objects_live, i)
109 : {
110 264324581 : ira_object_t obj = ira_object_id_map[i];
111 :
112 265982220 : if (ignore_reg_for_conflicts != NULL_RTX
113 173583528 : && REGNO (ignore_reg_for_conflicts)
114 173583528 : == (unsigned int) ALLOCNO_REGNO (OBJECT_ALLOCNO (obj)))
115 1657639 : continue;
116 :
117 262666942 : SET_HARD_REG_BIT (OBJECT_CONFLICT_HARD_REGS (obj), regno);
118 262666942 : SET_HARD_REG_BIT (OBJECT_TOTAL_CONFLICT_HARD_REGS (obj), regno);
119 : }
120 15021498 : CLEAR_HARD_REG_BIT (hard_regs_live, regno);
121 15021498 : }
122 :
123 : /* Record object OBJ as now being live. Set a bit for it in objects_live,
124 : and start a new live range for it if necessary. */
125 : static void
126 242400684 : make_object_live (ira_object_t obj)
127 : {
128 242400684 : sparseset_set_bit (objects_live, OBJECT_CONFLICT_ID (obj));
129 :
130 242400684 : live_range_t lr = OBJECT_LIVE_RANGES (obj);
131 242400684 : if (lr == NULL
132 205619343 : || (lr->finish != curr_point && lr->finish + 1 != curr_point))
133 54627166 : ira_add_live_range_to_object (obj, curr_point, -1);
134 242400684 : }
135 :
136 : /* Update ALLOCNO_EXCESS_PRESSURE_POINTS_NUM for the allocno
137 : associated with object OBJ. */
138 : static void
139 249786593 : update_allocno_pressure_excess_length (ira_object_t obj)
140 : {
141 249786593 : ira_allocno_t a = OBJECT_ALLOCNO (obj);
142 249786593 : int start, i;
143 249786593 : enum reg_class aclass, pclass, cl;
144 249786593 : live_range_t p;
145 :
146 249786593 : aclass = ALLOCNO_CLASS (a);
147 249786593 : pclass = ira_pressure_class_translate[aclass];
148 2453324466 : for (i = 0;
149 2453324466 : (cl = ira_reg_class_super_classes[pclass][i]) != LIM_REG_CLASSES;
150 : i++)
151 : {
152 2203537873 : if (! ira_reg_pressure_class_p[cl])
153 1958635349 : continue;
154 244902524 : if (high_pressure_start_point[cl] < 0)
155 74092187 : continue;
156 170810337 : p = OBJECT_LIVE_RANGES (obj);
157 170810337 : ira_assert (p != NULL);
158 170810337 : start = (high_pressure_start_point[cl] > p->start
159 170810337 : ? high_pressure_start_point[cl] : p->start);
160 170810337 : ALLOCNO_EXCESS_PRESSURE_POINTS_NUM (a) += curr_point - start + 1;
161 : }
162 249786593 : }
163 :
164 : /* Process the definition of object OBJ, which is associated with allocno A.
165 : This finishes the current live range for it. */
166 : static void
167 242400684 : make_object_dead (ira_object_t obj)
168 : {
169 242400684 : live_range_t lr;
170 242400684 : int regno;
171 242400684 : int ignore_regno = -1;
172 242400684 : int ignore_total_regno = -1;
173 242400684 : int end_regno = -1;
174 :
175 242400684 : sparseset_clear_bit (objects_live, OBJECT_CONFLICT_ID (obj));
176 :
177 : /* Check whether any part of IGNORE_REG_FOR_CONFLICTS already conflicts
178 : with OBJ. */
179 242400684 : if (ignore_reg_for_conflicts != NULL_RTX
180 242400684 : && REGNO (ignore_reg_for_conflicts) < FIRST_PSEUDO_REGISTER)
181 : {
182 3422421 : end_regno = END_REGNO (ignore_reg_for_conflicts);
183 3422421 : ignore_regno = ignore_total_regno = REGNO (ignore_reg_for_conflicts);
184 :
185 6844842 : for (regno = ignore_regno; regno < end_regno; regno++)
186 : {
187 3422421 : if (TEST_HARD_REG_BIT (OBJECT_CONFLICT_HARD_REGS (obj), regno))
188 517244 : ignore_regno = end_regno;
189 3422421 : if (TEST_HARD_REG_BIT (OBJECT_TOTAL_CONFLICT_HARD_REGS (obj), regno))
190 517244 : ignore_total_regno = end_regno;
191 : }
192 : }
193 :
194 969602736 : OBJECT_CONFLICT_HARD_REGS (obj) |= hard_regs_live;
195 245305861 : OBJECT_TOTAL_CONFLICT_HARD_REGS (obj) |= hard_regs_live;
196 :
197 : /* If IGNORE_REG_FOR_CONFLICTS did not already conflict with OBJ, make
198 : sure it still doesn't. */
199 245305861 : for (regno = ignore_regno; regno < end_regno; regno++)
200 2905177 : CLEAR_HARD_REG_BIT (OBJECT_CONFLICT_HARD_REGS (obj), regno);
201 245305861 : for (regno = ignore_total_regno; regno < end_regno; regno++)
202 2905177 : CLEAR_HARD_REG_BIT (OBJECT_TOTAL_CONFLICT_HARD_REGS (obj), regno);
203 :
204 242400684 : lr = OBJECT_LIVE_RANGES (obj);
205 242400684 : ira_assert (lr != NULL);
206 242400684 : lr->finish = curr_point;
207 242400684 : update_allocno_pressure_excess_length (obj);
208 242400684 : }
209 :
210 : /* The current register pressures for each pressure class for the current
211 : basic block. */
212 : static int curr_reg_pressure[N_REG_CLASSES];
213 :
214 : /* Record that register pressure for PCLASS increased by N registers.
215 : Update the current register pressure, maximal register pressure for
216 : the current BB and the start point of the register pressure
217 : excess. */
218 : static void
219 258992795 : inc_register_pressure (enum reg_class pclass, int n)
220 : {
221 258992795 : int i;
222 258992795 : enum reg_class cl;
223 :
224 2542718208 : for (i = 0;
225 2542718208 : (cl = ira_reg_class_super_classes[pclass][i]) != LIM_REG_CLASSES;
226 : i++)
227 : {
228 2283725413 : if (! ira_reg_pressure_class_p[cl])
229 2029363820 : continue;
230 254361593 : curr_reg_pressure[cl] += n;
231 254361593 : if (high_pressure_start_point[cl] < 0
232 105344396 : && (curr_reg_pressure[cl] > ira_class_hard_regs_num[cl]))
233 1768520 : high_pressure_start_point[cl] = curr_point;
234 254361593 : if (curr_bb_node->reg_pressure[cl] < curr_reg_pressure[cl])
235 219682328 : curr_bb_node->reg_pressure[cl] = curr_reg_pressure[cl];
236 : }
237 258992795 : }
238 :
239 : /* Record that register pressure for PCLASS has decreased by NREGS
240 : registers; update current register pressure, start point of the
241 : register pressure excess, and register pressure excess length for
242 : living allocnos. */
243 :
244 : static void
245 52485363 : dec_register_pressure (enum reg_class pclass, int nregs)
246 : {
247 52485363 : int i;
248 52485363 : unsigned int j;
249 52485363 : enum reg_class cl;
250 52485363 : bool set_p = false;
251 :
252 52485363 : for (i = 0;
253 509481498 : (cl = ira_reg_class_super_classes[pclass][i]) != LIM_REG_CLASSES;
254 : i++)
255 : {
256 456996135 : if (! ira_reg_pressure_class_p[cl])
257 405000641 : continue;
258 51995494 : curr_reg_pressure[cl] -= nregs;
259 51995494 : ira_assert (curr_reg_pressure[cl] >= 0);
260 51995494 : if (high_pressure_start_point[cl] >= 0
261 4681180 : && curr_reg_pressure[cl] <= ira_class_hard_regs_num[cl])
262 456996135 : set_p = true;
263 : }
264 52485363 : if (set_p)
265 : {
266 7867391 : EXECUTE_IF_SET_IN_SPARSESET (objects_live, j)
267 7385909 : update_allocno_pressure_excess_length (ira_object_id_map[j]);
268 4583242 : for (i = 0;
269 5064724 : (cl = ira_reg_class_super_classes[pclass][i]) != LIM_REG_CLASSES;
270 : i++)
271 : {
272 4583242 : if (! ira_reg_pressure_class_p[cl])
273 4101760 : continue;
274 481482 : if (high_pressure_start_point[cl] >= 0
275 481482 : && curr_reg_pressure[cl] <= ira_class_hard_regs_num[cl])
276 481482 : high_pressure_start_point[cl] = -1;
277 : }
278 : }
279 52485363 : }
280 :
281 : /* Determine from the objects_live bitmap whether REGNO is currently live,
282 : and occupies only one object. Return false if we have no information. */
283 : static bool
284 120056 : pseudo_regno_single_word_and_live_p (int regno)
285 : {
286 120056 : ira_allocno_t a = ira_curr_regno_allocno_map[regno];
287 120056 : ira_object_t obj;
288 :
289 120056 : if (a == NULL)
290 : return false;
291 120056 : if (ALLOCNO_NUM_OBJECTS (a) > 1)
292 : return false;
293 :
294 120056 : obj = ALLOCNO_OBJECT (a, 0);
295 :
296 120056 : return sparseset_bit_p (objects_live, OBJECT_CONFLICT_ID (obj));
297 : }
298 :
299 : /* Mark the pseudo register REGNO as live. Update all information about
300 : live ranges and register pressure. */
301 : static void
302 227025019 : mark_pseudo_regno_live (int regno)
303 : {
304 227025019 : ira_allocno_t a = ira_curr_regno_allocno_map[regno];
305 227025019 : enum reg_class pclass;
306 227025019 : int i, n, nregs;
307 :
308 227025019 : if (a == NULL)
309 : return;
310 :
311 : /* Invalidate because it is referenced. */
312 227025019 : allocno_saved_at_call[ALLOCNO_NUM (a)] = 0;
313 :
314 227025019 : n = ALLOCNO_NUM_OBJECTS (a);
315 227025019 : pclass = ira_pressure_class_translate[ALLOCNO_CLASS (a)];
316 227025019 : nregs = ira_reg_class_max_nregs[ALLOCNO_CLASS (a)][ALLOCNO_MODE (a)];
317 227025019 : if (n > 1)
318 : {
319 : /* We track every subobject separately. */
320 69873332 : gcc_assert (nregs == n);
321 : nregs = 1;
322 : }
323 :
324 523923370 : for (i = 0; i < n; i++)
325 : {
326 296898351 : ira_object_t obj = ALLOCNO_OBJECT (a, i);
327 :
328 296898351 : if (sparseset_bit_p (objects_live, OBJECT_CONFLICT_ID (obj)))
329 54813544 : continue;
330 :
331 242084807 : inc_register_pressure (pclass, nregs);
332 242084807 : make_object_live (obj);
333 : }
334 : }
335 :
336 : /* Like mark_pseudo_regno_live, but try to only mark one subword of
337 : the pseudo as live. SUBWORD indicates which; a value of 0
338 : indicates the low part. */
339 : static void
340 843292 : mark_pseudo_regno_subword_live (int regno, int subword)
341 : {
342 843292 : ira_allocno_t a = ira_curr_regno_allocno_map[regno];
343 843292 : int n;
344 843292 : enum reg_class pclass;
345 843292 : ira_object_t obj;
346 :
347 843292 : if (a == NULL)
348 : return;
349 :
350 : /* Invalidate because it is referenced. */
351 843292 : allocno_saved_at_call[ALLOCNO_NUM (a)] = 0;
352 :
353 843292 : n = ALLOCNO_NUM_OBJECTS (a);
354 843292 : if (n == 1)
355 : {
356 39687 : mark_pseudo_regno_live (regno);
357 39687 : return;
358 : }
359 :
360 803605 : pclass = ira_pressure_class_translate[ALLOCNO_CLASS (a)];
361 803605 : gcc_assert
362 : (n == ira_reg_class_max_nregs[ALLOCNO_CLASS (a)][ALLOCNO_MODE (a)]);
363 803605 : obj = ALLOCNO_OBJECT (a, subword);
364 :
365 803605 : if (sparseset_bit_p (objects_live, OBJECT_CONFLICT_ID (obj)))
366 : return;
367 :
368 315877 : inc_register_pressure (pclass, 1);
369 315877 : make_object_live (obj);
370 : }
371 :
372 : /* Mark the register REG as live. Store a 1 in hard_regs_live for
373 : this register, record how many consecutive hardware registers it
374 : actually needs. */
375 : static void
376 103369725 : mark_hard_reg_live (rtx reg)
377 : {
378 103369725 : int regno = REGNO (reg);
379 :
380 103369725 : if (! TEST_HARD_REG_BIT (ira_no_alloc_regs, regno))
381 : {
382 31347594 : int last = END_REGNO (reg);
383 31347594 : enum reg_class aclass, pclass;
384 :
385 62695188 : while (regno < last)
386 : {
387 31347594 : if (! TEST_HARD_REG_BIT (hard_regs_live, regno)
388 31347594 : && ! TEST_HARD_REG_BIT (eliminable_regset, regno))
389 : {
390 16592111 : aclass = ira_hard_regno_allocno_class[regno];
391 16592111 : pclass = ira_pressure_class_translate[aclass];
392 16592111 : inc_register_pressure (pclass, 1);
393 16592111 : make_hard_regno_live (regno);
394 : }
395 31347594 : regno++;
396 : }
397 : }
398 103369725 : }
399 :
400 : /* Mark a pseudo, or one of its subwords, as live. REGNO is the pseudo's
401 : register number; ORIG_REG is the access in the insn, which may be a
402 : subreg. */
403 : static void
404 87407653 : mark_pseudo_reg_live (rtx orig_reg, unsigned regno)
405 : {
406 87407653 : if (read_modify_subreg_p (orig_reg))
407 : {
408 1256538 : mark_pseudo_regno_subword_live (regno,
409 843292 : subreg_lowpart_p (orig_reg) ? 0 : 1);
410 : }
411 : else
412 86564361 : mark_pseudo_regno_live (regno);
413 87407653 : }
414 :
415 : /* Mark the register referenced by use or def REF as live. */
416 : static void
417 188920496 : mark_ref_live (df_ref ref)
418 : {
419 188920496 : rtx reg = DF_REF_REG (ref);
420 188920496 : rtx orig_reg = reg;
421 :
422 188920496 : if (GET_CODE (reg) == SUBREG)
423 3034825 : reg = SUBREG_REG (reg);
424 :
425 188920496 : if (REGNO (reg) >= FIRST_PSEUDO_REGISTER)
426 85550771 : mark_pseudo_reg_live (orig_reg, REGNO (reg));
427 : else
428 103369725 : mark_hard_reg_live (reg);
429 188920496 : }
430 :
431 : /* Mark the pseudo register REGNO as dead. Update all information about
432 : live ranges and register pressure. */
433 : static void
434 35849232 : mark_pseudo_regno_dead (int regno)
435 : {
436 35849232 : ira_allocno_t a = ira_curr_regno_allocno_map[regno];
437 35849232 : int n, i, nregs;
438 35849232 : enum reg_class cl;
439 :
440 35849232 : if (a == NULL)
441 : return;
442 :
443 : /* Invalidate because it is referenced. */
444 35849232 : allocno_saved_at_call[ALLOCNO_NUM (a)] = 0;
445 :
446 35849232 : n = ALLOCNO_NUM_OBJECTS (a);
447 35849232 : cl = ira_pressure_class_translate[ALLOCNO_CLASS (a)];
448 35849232 : nregs = ira_reg_class_max_nregs[ALLOCNO_CLASS (a)][ALLOCNO_MODE (a)];
449 35849232 : if (n > 1)
450 : {
451 : /* We track every subobject separately. */
452 1285253 : gcc_assert (nregs == n);
453 : nregs = 1;
454 : }
455 72983717 : for (i = 0; i < n; i++)
456 : {
457 37134485 : ira_object_t obj = ALLOCNO_OBJECT (a, i);
458 37134485 : if (!sparseset_bit_p (objects_live, OBJECT_CONFLICT_ID (obj)))
459 3548 : continue;
460 :
461 37130937 : dec_register_pressure (cl, nregs);
462 37130937 : make_object_dead (obj);
463 : }
464 : }
465 :
466 : /* Like mark_pseudo_regno_dead, but called when we know that only part of the
467 : register dies. SUBWORD indicates which; a value of 0 indicates the low part. */
468 : static void
469 337073 : mark_pseudo_regno_subword_dead (int regno, int subword)
470 : {
471 337073 : ira_allocno_t a = ira_curr_regno_allocno_map[regno];
472 337073 : int n;
473 337073 : enum reg_class cl;
474 337073 : ira_object_t obj;
475 :
476 337073 : if (a == NULL)
477 : return;
478 :
479 : /* Invalidate because it is referenced. */
480 337073 : allocno_saved_at_call[ALLOCNO_NUM (a)] = 0;
481 :
482 337073 : n = ALLOCNO_NUM_OBJECTS (a);
483 337073 : if (n == 1)
484 : /* The allocno as a whole doesn't die in this case. */
485 : return;
486 :
487 332928 : cl = ira_pressure_class_translate[ALLOCNO_CLASS (a)];
488 332928 : gcc_assert
489 : (n == ira_reg_class_max_nregs[ALLOCNO_CLASS (a)][ALLOCNO_MODE (a)]);
490 :
491 332928 : obj = ALLOCNO_OBJECT (a, subword);
492 332928 : if (!sparseset_bit_p (objects_live, OBJECT_CONFLICT_ID (obj)))
493 : return;
494 :
495 332928 : dec_register_pressure (cl, 1);
496 332928 : make_object_dead (obj);
497 : }
498 :
499 : /* Process the definition of hard register REG. This updates hard_regs_live
500 : and hard reg conflict information for living allocnos. */
501 : static void
502 47058934 : mark_hard_reg_dead (rtx reg)
503 : {
504 47058934 : int regno = REGNO (reg);
505 :
506 47058934 : if (! TEST_HARD_REG_BIT (ira_no_alloc_regs, regno))
507 : {
508 15023516 : int last = END_REGNO (reg);
509 15023516 : enum reg_class aclass, pclass;
510 :
511 30047032 : while (regno < last)
512 : {
513 15023516 : if (TEST_HARD_REG_BIT (hard_regs_live, regno))
514 : {
515 15021498 : aclass = ira_hard_regno_allocno_class[regno];
516 15021498 : pclass = ira_pressure_class_translate[aclass];
517 15021498 : dec_register_pressure (pclass, 1);
518 15021498 : make_hard_regno_dead (regno);
519 : }
520 15023516 : regno++;
521 : }
522 : }
523 47058934 : }
524 :
525 : /* Mark a pseudo, or one of its subwords, as dead. REGNO is the pseudo's
526 : register number; ORIG_REG is the access in the insn, which may be a
527 : subreg. */
528 : static void
529 36186305 : mark_pseudo_reg_dead (rtx orig_reg, unsigned regno)
530 : {
531 36186305 : if (read_modify_subreg_p (orig_reg))
532 : {
533 505953 : mark_pseudo_regno_subword_dead (regno,
534 337073 : subreg_lowpart_p (orig_reg) ? 0 : 1);
535 : }
536 : else
537 35849232 : mark_pseudo_regno_dead (regno);
538 36186305 : }
539 :
540 : /* Mark the register referenced by definition DEF as dead, if the
541 : definition is a total one. */
542 : static void
543 81392594 : mark_ref_dead (df_ref def)
544 : {
545 81392594 : rtx reg = DF_REF_REG (def);
546 81392594 : rtx orig_reg = reg;
547 :
548 81392594 : if (DF_REF_FLAGS_IS_SET (def, DF_REF_CONDITIONAL))
549 : return;
550 :
551 81392594 : if (GET_CODE (reg) == SUBREG)
552 915109 : reg = SUBREG_REG (reg);
553 :
554 81392594 : if (DF_REF_FLAGS_IS_SET (def, DF_REF_PARTIAL)
555 81392594 : && (GET_CODE (orig_reg) != SUBREG
556 327771 : || REGNO (reg) < FIRST_PSEUDO_REGISTER
557 327771 : || !read_modify_subreg_p (orig_reg)))
558 4237 : return;
559 :
560 81388357 : if (REGNO (reg) >= FIRST_PSEUDO_REGISTER)
561 34329423 : mark_pseudo_reg_dead (orig_reg, REGNO (reg));
562 : else
563 47058934 : mark_hard_reg_dead (reg);
564 : }
565 :
566 : /* If REG is a pseudo or a subreg of it, and the class of its allocno
567 : intersects CL, make a conflict with pseudo DREG. ORIG_DREG is the
568 : rtx actually accessed, it may be identical to DREG or a subreg of it.
569 : Advance the current program point before making the conflict if
570 : ADVANCE_P. Return TRUE if we will need to advance the current
571 : program point. */
572 : static bool
573 2885176 : make_pseudo_conflict (rtx reg, enum reg_class cl, rtx dreg, rtx orig_dreg,
574 : bool advance_p)
575 : {
576 2885176 : rtx orig_reg = reg;
577 2885176 : ira_allocno_t a;
578 :
579 2885176 : if (GET_CODE (reg) == SUBREG)
580 84442 : reg = SUBREG_REG (reg);
581 :
582 2885176 : if (! REG_P (reg) || REGNO (reg) < FIRST_PSEUDO_REGISTER)
583 : return advance_p;
584 :
585 1021262 : a = ira_curr_regno_allocno_map[REGNO (reg)];
586 1021262 : if (! reg_classes_intersect_p (cl, ALLOCNO_CLASS (a)))
587 : return advance_p;
588 :
589 928441 : if (advance_p)
590 883767 : curr_point++;
591 :
592 928441 : mark_pseudo_reg_live (orig_reg, REGNO (reg));
593 928441 : mark_pseudo_reg_live (orig_dreg, REGNO (dreg));
594 928441 : mark_pseudo_reg_dead (orig_reg, REGNO (reg));
595 928441 : mark_pseudo_reg_dead (orig_dreg, REGNO (dreg));
596 :
597 928441 : return false;
598 : }
599 :
600 : /* Check and make if necessary conflicts for pseudo DREG of class
601 : DEF_CL of the current insn with input operand USE of class USE_CL.
602 : ORIG_DREG is the rtx actually accessed, it may be identical to
603 : DREG or a subreg of it. Advance the current program point before
604 : making the conflict if ADVANCE_P. Return TRUE if we will need to
605 : advance the current program point. */
606 : static bool
607 2932042 : check_and_make_def_use_conflict (rtx dreg, rtx orig_dreg,
608 : enum reg_class def_cl, int use,
609 : enum reg_class use_cl, bool advance_p)
610 : {
611 2932042 : if (! reg_classes_intersect_p (def_cl, use_cl))
612 : return advance_p;
613 :
614 2869663 : advance_p = make_pseudo_conflict (recog_data.operand[use],
615 : use_cl, dreg, orig_dreg, advance_p);
616 :
617 : /* Reload may end up swapping commutative operands, so you
618 : have to take both orderings into account. The
619 : constraints for the two operands can be completely
620 : different. (Indeed, if the constraints for the two
621 : operands are the same for all alternatives, there's no
622 : point marking them as commutative.) */
623 2869663 : if (use < recog_data.n_operands - 1
624 1109963 : && recog_data.constraints[use][0] == '%')
625 6464 : advance_p
626 6464 : = make_pseudo_conflict (recog_data.operand[use + 1],
627 : use_cl, dreg, orig_dreg, advance_p);
628 2869663 : if (use >= 1
629 2869365 : && recog_data.constraints[use - 1][0] == '%')
630 9049 : advance_p
631 9049 : = make_pseudo_conflict (recog_data.operand[use - 1],
632 : use_cl, dreg, orig_dreg, advance_p);
633 : return advance_p;
634 : }
635 :
636 : /* Check and make if necessary conflicts for definition DEF of class
637 : DEF_CL of the current insn with input operands. Process only
638 : constraints of alternative ALT.
639 :
640 : One of three things is true when this function is called:
641 :
642 : (1) DEF is an earlyclobber for alternative ALT. Input operands then
643 : conflict with DEF in ALT unless they explicitly match DEF via 0-9
644 : constraints.
645 :
646 : (2) DEF matches (via 0-9 constraints) an operand that is an
647 : earlyclobber for alternative ALT. Other input operands then
648 : conflict with DEF in ALT.
649 :
650 : (3) [FOR_TIE_P] Some input operand X matches DEF for alternative ALT.
651 : Input operands with a different value from X then conflict with
652 : DEF in ALT.
653 :
654 : However, there's still a judgement call to make when deciding
655 : whether a conflict in ALT is important enough to be reflected
656 : in the pan-alternative allocno conflict set. */
657 : static void
658 14446798 : check_and_make_def_conflict (int alt, int def, enum reg_class def_cl,
659 : bool for_tie_p)
660 : {
661 14446798 : int use, use_match;
662 14446798 : ira_allocno_t a;
663 14446798 : enum reg_class use_cl, acl;
664 14446798 : bool advance_p;
665 14446798 : rtx dreg = recog_data.operand[def];
666 14446798 : rtx orig_dreg = dreg;
667 :
668 14446798 : if (def_cl == NO_REGS)
669 : return;
670 :
671 14446798 : if (GET_CODE (dreg) == SUBREG)
672 112694 : dreg = SUBREG_REG (dreg);
673 :
674 14446798 : if (! REG_P (dreg) || REGNO (dreg) < FIRST_PSEUDO_REGISTER)
675 : return;
676 :
677 12230219 : a = ira_curr_regno_allocno_map[REGNO (dreg)];
678 12230219 : acl = ALLOCNO_CLASS (a);
679 12230219 : if (! reg_classes_intersect_p (acl, def_cl))
680 : return;
681 :
682 12033135 : advance_p = true;
683 :
684 12033135 : int n_operands = recog_data.n_operands;
685 12033135 : const operand_alternative *op_alt = &recog_op_alt[alt * n_operands];
686 49813744 : for (use = 0; use < n_operands; use++)
687 : {
688 37780609 : int alt1;
689 :
690 37780609 : if (use == def || recog_data.operand_type[use] == OP_OUT)
691 12191455 : continue;
692 :
693 : /* An earlyclobber on DEF doesn't apply to an input operand X if X
694 : explicitly matches DEF, but it applies to other input operands
695 : even if they happen to be the same value as X.
696 :
697 : In contrast, if an input operand X is tied to a non-earlyclobber
698 : DEF, there's no conflict with other input operands that have the
699 : same value as X. */
700 37547157 : if (op_alt[use].matches == def
701 25589154 : || (for_tie_p
702 13379363 : && rtx_equal_p (recog_data.operand[use],
703 13379363 : recog_data.operand[op_alt[def].matched])))
704 11958003 : continue;
705 :
706 13631151 : if (op_alt[use].anything_ok)
707 : use_cl = ALL_REGS;
708 : else
709 11951021 : use_cl = op_alt[use].cl;
710 11951021 : if (use_cl == NO_REGS)
711 4781957 : continue;
712 :
713 : /* If DEF is simply a tied operand, ignore cases in which this
714 : alternative requires USE to have a likely-spilled class.
715 : Adding a conflict would just constrain USE further if DEF
716 : happens to be allocated first. */
717 8849194 : if (for_tie_p && targetm.class_likely_spilled_p (use_cl))
718 1013167 : continue;
719 :
720 : /* If there's any alternative that allows USE to match DEF, do not
721 : record a conflict. If that causes us to create an invalid
722 : instruction due to the earlyclobber, reload must fix it up.
723 :
724 : Likewise, if we're treating a tied DEF like a partial earlyclobber,
725 : do not record a conflict if there's another alternative in which
726 : DEF is neither tied nor earlyclobber. */
727 21023827 : for (alt1 = 0; alt1 < recog_data.n_alternatives; alt1++)
728 : {
729 18091786 : if (!TEST_BIT (preferred_alternatives, alt1))
730 8707704 : continue;
731 9384082 : const operand_alternative *op_alt1
732 9384082 : = &recog_op_alt[alt1 * n_operands];
733 9384082 : if (op_alt1[use].matches == def
734 7536384 : || (use < n_operands - 1
735 2825071 : && recog_data.constraints[use][0] == '%'
736 8120 : && op_alt1[use + 1].matches == def)
737 7536384 : || (use >= 1
738 7534864 : && recog_data.constraints[use - 1][0] == '%'
739 3061622 : && op_alt1[use - 1].matches == def))
740 : break;
741 4485467 : if (for_tie_p
742 4275363 : && !op_alt1[def].earlyclobber
743 4274203 : && op_alt1[def].matched < 0
744 25005 : && alternative_class (op_alt1, def) != NO_REGS
745 4510472 : && alternative_class (op_alt1, use) != NO_REGS)
746 : break;
747 : }
748 :
749 7836027 : if (alt1 < recog_data.n_alternatives)
750 4903986 : continue;
751 :
752 2932041 : advance_p = check_and_make_def_use_conflict (dreg, orig_dreg, def_cl,
753 : use, use_cl, advance_p);
754 :
755 2932041 : if ((use_match = op_alt[use].matches) >= 0)
756 : {
757 1 : gcc_checking_assert (use_match != def);
758 :
759 1 : if (op_alt[use_match].anything_ok)
760 : use_cl = ALL_REGS;
761 : else
762 1 : use_cl = op_alt[use_match].cl;
763 1 : advance_p = check_and_make_def_use_conflict (dreg, orig_dreg, def_cl,
764 : use, use_cl, advance_p);
765 : }
766 : }
767 : }
768 :
769 : /* Make conflicts of early clobber pseudo registers of the current
770 : insn with its inputs. Avoid introducing unnecessary conflicts by
771 : checking classes of the constraints and pseudos because otherwise
772 : significant code degradation is possible for some targets.
773 :
774 : For these purposes, tying an input to an output makes that output act
775 : like an earlyclobber for inputs with a different value, since the output
776 : register then has a predetermined purpose on input to the instruction. */
777 : static void
778 84136029 : make_early_clobber_and_input_conflicts (void)
779 : {
780 84136029 : int alt;
781 84136029 : int def, def_match;
782 84136029 : enum reg_class def_cl;
783 :
784 84136029 : int n_alternatives = recog_data.n_alternatives;
785 84136029 : int n_operands = recog_data.n_operands;
786 84136029 : const operand_alternative *op_alt = recog_op_alt;
787 1159497533 : for (alt = 0; alt < n_alternatives; alt++, op_alt += n_operands)
788 1075361504 : if (TEST_BIT (preferred_alternatives, alt))
789 388647200 : for (def = 0; def < n_operands; def++)
790 : {
791 268242219 : if (op_alt[def].anything_ok)
792 : def_cl = ALL_REGS;
793 : else
794 254082493 : def_cl = op_alt[def].cl;
795 254082493 : if (def_cl != NO_REGS)
796 : {
797 212212941 : if (op_alt[def].earlyclobber)
798 140318 : check_and_make_def_conflict (alt, def, def_cl, false);
799 212072623 : else if (op_alt[def].matched >= 0
800 212072623 : && !targetm.class_likely_spilled_p (def_cl))
801 14269956 : check_and_make_def_conflict (alt, def, def_cl, true);
802 : }
803 :
804 268242219 : if ((def_match = op_alt[def].matches) >= 0
805 268242219 : && (op_alt[def_match].earlyclobber
806 14956734 : || op_alt[def].earlyclobber))
807 : {
808 36524 : if (op_alt[def_match].anything_ok)
809 : def_cl = ALL_REGS;
810 : else
811 36524 : def_cl = op_alt[def_match].cl;
812 36524 : check_and_make_def_conflict (alt, def, def_cl, false);
813 : }
814 : }
815 84136029 : }
816 :
817 : /* Mark early clobber hard registers of the current INSN as live (if
818 : LIVE_P) or dead. Return true if there are such registers. */
819 : static bool
820 94808798 : mark_hard_reg_early_clobbers (rtx_insn *insn, bool live_p)
821 : {
822 94808798 : df_ref def;
823 94808798 : bool set_p = false;
824 :
825 680016677 : FOR_EACH_INSN_DEF (def, insn)
826 585207879 : if (DF_REF_FLAGS_IS_SET (def, DF_REF_MUST_CLOBBER))
827 : {
828 21783755 : rtx dreg = DF_REF_REG (def);
829 :
830 21783755 : if (GET_CODE (dreg) == SUBREG)
831 0 : dreg = SUBREG_REG (dreg);
832 21783755 : if (! REG_P (dreg) || REGNO (dreg) >= FIRST_PSEUDO_REGISTER)
833 145565 : continue;
834 :
835 : /* Hard register clobbers are believed to be early clobber
836 : because there is no way to say that non-operand hard
837 : register clobbers are not early ones. */
838 21638190 : if (live_p)
839 10819095 : mark_ref_live (def);
840 : else
841 10819095 : mark_ref_dead (def);
842 : set_p = true;
843 : }
844 :
845 94808798 : return set_p;
846 : }
847 :
848 : /* Checks that CONSTRAINTS permits to use only one hard register. If
849 : it is so, the function returns the class of the hard register.
850 : Otherwise it returns NO_REGS. */
851 : static enum reg_class
852 178109840 : single_reg_class (const char *constraints, rtx op, rtx equiv_const)
853 : {
854 178109840 : int c;
855 178109840 : enum reg_class cl, next_cl;
856 178109840 : enum constraint_num cn;
857 :
858 178109840 : cl = NO_REGS;
859 178109840 : alternative_mask preferred = preferred_alternatives;
860 926458008 : while ((c = *constraints))
861 : {
862 912402845 : if (c == '#')
863 0 : preferred &= ~ALTERNATIVE_BIT (0);
864 912402845 : else if (c == ',')
865 249246181 : preferred >>= 1;
866 663156664 : else if (preferred & 1)
867 200665062 : switch (c)
868 : {
869 : case 'g':
870 : return NO_REGS;
871 :
872 180582843 : default:
873 : /* ??? Is this the best way to handle memory constraints? */
874 180582843 : cn = lookup_constraint (constraints);
875 180582843 : if (insn_extra_memory_constraint (cn)
876 168493846 : || insn_extra_special_memory_constraint (cn)
877 : || insn_extra_relaxed_memory_constraint (cn)
878 349076687 : || insn_extra_address_constraint (cn))
879 : return NO_REGS;
880 167916097 : if (constraint_satisfied_p (op, cn)
881 167916097 : || (equiv_const != NULL_RTX
882 0 : && CONSTANT_P (equiv_const)
883 0 : && constraint_satisfied_p (equiv_const, cn)))
884 14679141 : return NO_REGS;
885 153236956 : next_cl = reg_class_for_constraint (cn);
886 121849631 : if (next_cl == NO_REGS)
887 : break;
888 118629077 : if (cl == NO_REGS
889 118629077 : ? ira_class_singleton[next_cl][GET_MODE (op)] < 0
890 994626 : : (ira_class_singleton[cl][GET_MODE (op)]
891 994626 : != ira_class_singleton[next_cl][GET_MODE (op)]))
892 : return NO_REGS;
893 : cl = next_cl;
894 : break;
895 :
896 12936889 : case '0': case '1': case '2': case '3': case '4':
897 12936889 : case '5': case '6': case '7': case '8': case '9':
898 12936889 : {
899 12936889 : char *end;
900 12936889 : unsigned long dup = strtoul (constraints, &end, 10);
901 12936889 : constraints = end;
902 12936889 : next_cl
903 12936889 : = single_reg_class (recog_data.constraints[dup],
904 : recog_data.operand[dup], NULL_RTX);
905 12936889 : if (cl == NO_REGS
906 12936889 : ? ira_class_singleton[next_cl][GET_MODE (op)] < 0
907 18862 : : (ira_class_singleton[cl][GET_MODE (op)]
908 18862 : != ira_class_singleton[next_cl][GET_MODE (op)]))
909 12708680 : return NO_REGS;
910 228209 : cl = next_cl;
911 228209 : continue;
912 228209 : }
913 : }
914 748119959 : constraints += CONSTRAINT_LEN (c, constraints);
915 : }
916 : return cl;
917 : }
918 :
919 : /* The function checks that operand OP_NUM of the current insn can use
920 : only one hard register. If it is so, the function returns the
921 : class of the hard register. Otherwise it returns NO_REGS. */
922 : static enum reg_class
923 180335689 : single_reg_operand_class (int op_num)
924 : {
925 180335689 : if (op_num < 0 || recog_data.n_alternatives == 0)
926 : return NO_REGS;
927 165172951 : return single_reg_class (recog_data.constraints[op_num],
928 165172951 : recog_data.operand[op_num], NULL_RTX);
929 : }
930 :
931 : /* The function sets up hard register set *SET to hard registers which
932 : might be used by insn reloads because the constraints are too
933 : strict. */
934 : void
935 27728 : ira_implicitly_set_insn_hard_regs (HARD_REG_SET *set,
936 : alternative_mask preferred)
937 : {
938 27728 : int i, c, regno = 0;
939 27728 : enum reg_class cl;
940 27728 : rtx op;
941 27728 : machine_mode mode;
942 :
943 27728 : CLEAR_HARD_REG_SET (*set);
944 85729 : for (i = 0; i < recog_data.n_operands; i++)
945 : {
946 58001 : op = recog_data.operand[i];
947 :
948 58001 : if (GET_CODE (op) == SUBREG)
949 1118 : op = SUBREG_REG (op);
950 :
951 58001 : if (GET_CODE (op) == SCRATCH
952 58001 : || (REG_P (op) && (regno = REGNO (op)) >= FIRST_PSEUDO_REGISTER))
953 : {
954 38984 : const char *p = recog_data.constraints[i];
955 :
956 77968 : mode = (GET_CODE (op) == SCRATCH
957 38984 : ? GET_MODE (op) : PSEUDO_REGNO_MODE (regno));
958 38984 : cl = NO_REGS;
959 38984 : for (alternative_mask curr_preferred = preferred;
960 1427142 : (c = *p);
961 1388158 : p += CONSTRAINT_LEN (c, p))
962 1388158 : if (c == '#')
963 0 : curr_preferred &= ~ALTERNATIVE_BIT (0);
964 1388158 : else if (c == ',')
965 473324 : curr_preferred >>= 1;
966 914834 : else if (curr_preferred & 1)
967 : {
968 571716 : cl = reg_class_for_constraint (lookup_constraint (p));
969 247429 : if (cl != NO_REGS)
970 : {
971 : /* There is no register pressure problem if all of the
972 : regs in this class are fixed. */
973 243741 : int regno = ira_class_singleton[cl][mode];
974 243741 : if (regno >= 0)
975 1647 : add_to_hard_reg_set (set, mode, regno);
976 : }
977 327975 : else if (c == '{')
978 : {
979 0 : int regno = decode_hard_reg_constraint (p);
980 0 : gcc_assert (regno >= 0 && regno < FIRST_PSEUDO_REGISTER);
981 0 : add_to_hard_reg_set (set, mode, regno);
982 : }
983 : }
984 : }
985 : }
986 27728 : }
987 : /* Processes input operands, if IN_P, or output operands otherwise of
988 : the current insn with FREQ to find allocno which can use only one
989 : hard register and makes other currently living allocnos conflicting
990 : with the hard register. */
991 : static void
992 168272058 : process_single_reg_class_operands (bool in_p, int freq)
993 : {
994 168272058 : int i, regno;
995 168272058 : unsigned int px;
996 168272058 : enum reg_class cl;
997 168272058 : rtx operand;
998 168272058 : ira_allocno_t operand_a, a;
999 :
1000 528783556 : for (i = 0; i < recog_data.n_operands; i++)
1001 : {
1002 360511498 : operand = recog_data.operand[i];
1003 360511498 : if (in_p && recog_data.operand_type[i] != OP_IN
1004 61440838 : && recog_data.operand_type[i] != OP_INOUT)
1005 61360898 : continue;
1006 180255749 : if (! in_p && recog_data.operand_type[i] != OP_OUT
1007 118894851 : && recog_data.operand_type[i] != OP_INOUT)
1008 118814911 : continue;
1009 180335689 : cl = single_reg_operand_class (i);
1010 180335689 : if (cl == NO_REGS)
1011 179575137 : continue;
1012 :
1013 760552 : operand_a = NULL;
1014 :
1015 760552 : if (GET_CODE (operand) == SUBREG)
1016 59539 : operand = SUBREG_REG (operand);
1017 :
1018 760552 : if (REG_P (operand)
1019 760552 : && (regno = REGNO (operand)) >= FIRST_PSEUDO_REGISTER)
1020 : {
1021 755994 : enum reg_class aclass;
1022 :
1023 755994 : operand_a = ira_curr_regno_allocno_map[regno];
1024 755994 : aclass = ALLOCNO_CLASS (operand_a);
1025 755994 : if (ira_class_subset_p[cl][aclass])
1026 : {
1027 : /* View the desired allocation of OPERAND as:
1028 :
1029 : (REG:YMODE YREGNO),
1030 :
1031 : a simplification of:
1032 :
1033 : (subreg:YMODE (reg:XMODE XREGNO) OFFSET). */
1034 747621 : machine_mode ymode, xmode;
1035 747621 : int xregno, yregno;
1036 747621 : poly_int64 offset;
1037 :
1038 747621 : xmode = recog_data.operand_mode[i];
1039 747621 : xregno = ira_class_singleton[cl][xmode];
1040 747621 : gcc_assert (xregno >= 0);
1041 747621 : ymode = ALLOCNO_MODE (operand_a);
1042 747621 : offset = subreg_lowpart_offset (ymode, xmode);
1043 747621 : yregno = simplify_subreg_regno (xregno, xmode, offset, ymode);
1044 747621 : if (yregno >= 0
1045 747621 : && ira_class_hard_reg_index[aclass][yregno] >= 0)
1046 : {
1047 747621 : int cost;
1048 :
1049 747621 : ira_allocate_and_set_costs
1050 747621 : (&ALLOCNO_CONFLICT_HARD_REG_COSTS (operand_a),
1051 : aclass, 0);
1052 747621 : ira_init_register_move_cost_if_necessary (xmode);
1053 1495242 : cost = freq * (in_p
1054 747621 : ? ira_register_move_cost[xmode][aclass][cl]
1055 433693 : : ira_register_move_cost[xmode][cl][aclass]);
1056 747621 : ALLOCNO_CONFLICT_HARD_REG_COSTS (operand_a)
1057 747621 : [ira_class_hard_reg_index[aclass][yregno]] -= cost;
1058 : }
1059 : }
1060 : }
1061 :
1062 29768792 : EXECUTE_IF_SET_IN_SPARSESET (objects_live, px)
1063 : {
1064 29008240 : ira_object_t obj = ira_object_id_map[px];
1065 29008240 : a = OBJECT_ALLOCNO (obj);
1066 29008240 : if (a != operand_a)
1067 : {
1068 : /* We could increase costs of A instead of making it
1069 : conflicting with the hard register. But it works worse
1070 : because it will be spilled in reload in anyway. */
1071 112867028 : OBJECT_CONFLICT_HARD_REGS (obj) |= reg_class_contents[cl];
1072 29008240 : OBJECT_TOTAL_CONFLICT_HARD_REGS (obj) |= reg_class_contents[cl];
1073 : }
1074 : }
1075 : }
1076 168272058 : }
1077 :
1078 : /* Go through the operands of the extracted insn looking for operand
1079 : alternatives that apply a register filter. Record any such filters
1080 : in the operand's allocno. */
1081 : static void
1082 84136029 : process_register_constraint_filters ()
1083 : {
1084 264391778 : for (int opno = 0; opno < recog_data.n_operands; ++opno)
1085 : {
1086 180255749 : rtx op = recog_data.operand[opno];
1087 180255749 : if (SUBREG_P (op))
1088 2994601 : op = SUBREG_REG (op);
1089 180255749 : if (REG_P (op) && !HARD_REGISTER_P (op))
1090 : {
1091 74423009 : ira_allocno_t a = ira_curr_regno_allocno_map[REGNO (op)];
1092 1058741686 : for (int alt = 0; alt < recog_data.n_alternatives; alt++)
1093 : {
1094 984318677 : if (!TEST_BIT (preferred_alternatives, alt))
1095 861217900 : continue;
1096 :
1097 123100777 : auto *op_alt = &recog_op_alt[alt * recog_data.n_operands];
1098 123100777 : auto cl = alternative_class (op_alt, opno);
1099 : /* The two extremes are easy:
1100 :
1101 : - We should record the filter if CL matches the
1102 : allocno class.
1103 :
1104 : - We should ignore the filter if CL and the allocno class
1105 : are disjoint. We'll either pick a different alternative
1106 : or reload the operand.
1107 :
1108 : Things are trickier if the classes overlap. However:
1109 :
1110 : - If the allocno class includes registers that are not
1111 : in CL, some choices of hard register will need a reload
1112 : anyway. It isn't obvious that reloads due to filters
1113 : are worse than reloads due to regnos being outside CL.
1114 :
1115 : - Conversely, if the allocno class is a subset of CL,
1116 : any allocation will satisfy the class requirement.
1117 : We should try to make sure it satisfies the filter
1118 : requirement too. This is useful if, for example,
1119 : an allocno needs to be in "low" registers to satisfy
1120 : some uses, and its allocno class is therefore those
1121 : low registers, but the allocno is elsewhere allowed
1122 : to be in any even-numbered register. Picking an
1123 : even-numbered low register satisfies both types of use. */
1124 123100777 : if (!ira_class_subset_p[ALLOCNO_CLASS (a)][cl])
1125 28878322 : continue;
1126 :
1127 94222455 : auto filters = alternative_register_filters (op_alt, opno);
1128 94222455 : if (!filters)
1129 94222455 : continue;
1130 :
1131 0 : filters |= ALLOCNO_REGISTER_FILTERS (a);
1132 0 : ALLOCNO_SET_REGISTER_FILTERS (a, filters);
1133 : }
1134 : }
1135 : }
1136 84136029 : }
1137 :
1138 : /* Append a dependent filter ID with mode MODE, referenced allocno
1139 : REF_ALLOCNO, hardreg REF_HARD_REGNO, and REF_MODE to allocno A. */
1140 :
1141 : void
1142 0 : ira_add_dependent_filter (ira_allocno_t a, int id,
1143 : machine_mode mode, ira_allocno_t ref_allocno,
1144 : unsigned int ref_hard_regno, machine_mode ref_mode)
1145 : {
1146 : /* Check if we already have the filter that should be added.
1147 : This is a linear search and the assumption is that we'll never
1148 : have more than a handful of dependent filters. Right now, the
1149 : maximum is 32 (see gensupport.cc). */
1150 0 : for (auto *filter = ALLOCNO_DEPENDENT_FILTERS (a);
1151 0 : filter;
1152 0 : filter = filter->next)
1153 0 : if (filter->id == id
1154 0 : && filter->ref_allocno == ref_allocno
1155 0 : && filter->ref_hard_regno == ref_hard_regno
1156 0 : && filter->mode == mode
1157 0 : && filter->ref_mode == ref_mode)
1158 : return;
1159 :
1160 0 : auto *filter = (ira_dependent_filter *)
1161 0 : ira_allocate (sizeof (ira_dependent_filter));
1162 0 : filter->id = id;
1163 0 : filter->ref_allocno = ref_allocno;
1164 0 : filter->ref_hard_regno = ref_hard_regno;
1165 0 : filter->mode = mode;
1166 0 : filter->ref_mode = ref_mode;
1167 0 : filter->next = ALLOCNO_DEPENDENT_FILTERS (a);
1168 0 : ALLOCNO_DEPENDENT_FILTERS (a) = filter;
1169 : }
1170 :
1171 : /* Walk the operand alternatives of the current insn. For each
1172 : operand with a dependent-filter constraint, add one
1173 : ira_dependent_filter in the appropriate allocno. */
1174 :
1175 : static void
1176 0 : process_dependent_filters ()
1177 : {
1178 0 : if (!NUM_DEPENDENT_FILTERS)
1179 0 : return;
1180 :
1181 : for (int opno = 0; opno < recog_data.n_operands; ++opno)
1182 : {
1183 : rtx op = recog_data.operand[opno];
1184 : if (SUBREG_P (op))
1185 : op = SUBREG_REG (op);
1186 : if (!REG_P (op) || HARD_REGISTER_P (op))
1187 : continue;
1188 :
1189 : ira_allocno_t a = ira_curr_regno_allocno_map[REGNO (op)];
1190 :
1191 : for (int alt = 0; alt < recog_data.n_alternatives; alt++)
1192 : {
1193 : if (!TEST_BIT (preferred_alternatives, alt))
1194 : continue;
1195 :
1196 : auto *op_alt = &recog_op_alt[alt * recog_data.n_operands];
1197 : auto cl = alternative_class (op_alt, opno);
1198 : if (!ira_class_subset_p[ALLOCNO_CLASS (a)][cl])
1199 : continue;
1200 :
1201 : auto dep_filter_mask = alternative_dependent_filters (op_alt, opno);
1202 : if (!dep_filter_mask)
1203 : continue;
1204 :
1205 : for (int id = 0; id < NUM_DEPENDENT_FILTERS; ++id)
1206 : {
1207 : if (!(dep_filter_mask & (1U << id)))
1208 : continue;
1209 :
1210 : int ref_opno = get_dependent_filter_ref (id);
1211 : if (ref_opno < 0 || ref_opno >= recog_data.n_operands)
1212 : continue;
1213 : rtx ref_op = recog_data.operand[ref_opno];
1214 : if (SUBREG_P (ref_op))
1215 : ref_op = SUBREG_REG (ref_op);
1216 : if (!REG_P (ref_op))
1217 : continue;
1218 :
1219 : ira_allocno_t ref_a = NULL;
1220 : unsigned int ref_hard_regno = INVALID_REGNUM;
1221 : if (HARD_REGISTER_P (ref_op))
1222 : ref_hard_regno = REGNO (ref_op);
1223 : else
1224 : ref_a = ira_curr_regno_allocno_map[REGNO (ref_op)];
1225 :
1226 : ira_add_dependent_filter (a, id, GET_MODE (op),
1227 : ref_a, ref_hard_regno,
1228 : GET_MODE (ref_op));
1229 : }
1230 : }
1231 : }
1232 : }
1233 :
1234 : /* Look through the CALL_INSN_FUNCTION_USAGE of a call insn INSN, and see if
1235 : we find a SET rtx that we can use to deduce that a register can be cheaply
1236 : caller-saved. Return such a register, or NULL_RTX if none is found. */
1237 : static rtx
1238 6052059 : find_call_crossed_cheap_reg (rtx_insn *insn)
1239 : {
1240 6052059 : rtx cheap_reg = NULL_RTX;
1241 6052059 : rtx exp = CALL_INSN_FUNCTION_USAGE (insn);
1242 :
1243 17778608 : while (exp != NULL)
1244 : {
1245 11878803 : rtx x = XEXP (exp, 0);
1246 11878803 : if (GET_CODE (x) == SET)
1247 : {
1248 : exp = x;
1249 : break;
1250 : }
1251 11726549 : exp = XEXP (exp, 1);
1252 : }
1253 6052059 : if (exp != NULL)
1254 : {
1255 152254 : basic_block bb = BLOCK_FOR_INSN (insn);
1256 152254 : rtx reg = SET_SRC (exp);
1257 152254 : rtx_insn *prev = PREV_INSN (insn);
1258 304525 : while (prev && !(INSN_P (prev)
1259 152254 : && BLOCK_FOR_INSN (prev) != bb))
1260 : {
1261 152271 : if (NONDEBUG_INSN_P (prev))
1262 : {
1263 152254 : rtx set = single_set (prev);
1264 :
1265 152254 : if (set && rtx_equal_p (SET_DEST (set), reg))
1266 : {
1267 152254 : rtx src = SET_SRC (set);
1268 120467 : if (!REG_P (src) || HARD_REGISTER_P (src)
1269 272310 : || !pseudo_regno_single_word_and_live_p (REGNO (src)))
1270 : break;
1271 33063 : if (!modified_between_p (src, prev, insn))
1272 6052059 : cheap_reg = src;
1273 : break;
1274 : }
1275 0 : if (set && rtx_equal_p (SET_SRC (set), reg))
1276 : {
1277 0 : rtx dest = SET_DEST (set);
1278 0 : if (!REG_P (dest) || HARD_REGISTER_P (dest)
1279 0 : || !pseudo_regno_single_word_and_live_p (REGNO (dest)))
1280 : break;
1281 0 : if (!modified_between_p (dest, prev, insn))
1282 6052059 : cheap_reg = dest;
1283 : break;
1284 : }
1285 :
1286 0 : if (reg_set_p (reg, prev))
1287 : break;
1288 : }
1289 17 : prev = PREV_INSN (prev);
1290 : }
1291 : }
1292 6052059 : return cheap_reg;
1293 : }
1294 :
1295 : /* Determine whether INSN is a register to register copy of the type where
1296 : we do not need to make the source and destiniation registers conflict.
1297 : If this is a copy instruction, then return the source reg. Otherwise,
1298 : return NULL_RTX. */
1299 : rtx
1300 308121469 : non_conflicting_reg_copy_p (rtx_insn *insn)
1301 : {
1302 : /* Reload has issues with overlapping pseudos being assigned to the
1303 : same hard register, so don't allow it. See PR87600 for details. */
1304 308121469 : if (!targetm.lra_p ())
1305 : return NULL_RTX;
1306 :
1307 308121469 : rtx set = single_set (insn);
1308 :
1309 : /* Disallow anything other than a simple register to register copy
1310 : that has no side effects. */
1311 308121469 : if (set == NULL_RTX
1312 292931189 : || !REG_P (SET_DEST (set))
1313 215405461 : || !REG_P (SET_SRC (set))
1314 380503266 : || side_effects_p (set))
1315 235739672 : return NULL_RTX;
1316 :
1317 72381797 : int dst_regno = REGNO (SET_DEST (set));
1318 72381797 : int src_regno = REGNO (SET_SRC (set));
1319 72381797 : machine_mode mode = GET_MODE (SET_DEST (set));
1320 :
1321 : /* By definition, a register does not conflict with itself, therefore we
1322 : do not have to handle it specially. Returning NULL_RTX now, helps
1323 : simplify the callers of this function. */
1324 72381797 : if (dst_regno == src_regno)
1325 : return NULL_RTX;
1326 :
1327 : /* Computing conflicts for register pairs is difficult to get right, so
1328 : for now, disallow it. */
1329 72381797 : if ((HARD_REGISTER_NUM_P (dst_regno)
1330 19701286 : && hard_regno_nregs (dst_regno, mode) != 1)
1331 91918336 : || (HARD_REGISTER_NUM_P (src_regno)
1332 10412260 : && hard_regno_nregs (src_regno, mode) != 1))
1333 : return NULL_RTX;
1334 :
1335 : return SET_SRC (set);
1336 : }
1337 :
1338 : #ifdef EH_RETURN_DATA_REGNO
1339 :
1340 : /* Add EH return hard registers as conflict hard registers to allocnos
1341 : living at end of BB. For most allocnos it is already done in
1342 : process_bb_node_lives when we processing input edges but it does
1343 : not work when and EH edge is edge out of the current region. This
1344 : function covers such out of region edges. */
1345 : static void
1346 14504565 : process_out_of_region_eh_regs (basic_block bb)
1347 : {
1348 14504565 : edge e;
1349 14504565 : edge_iterator ei;
1350 14504565 : unsigned int i;
1351 14504565 : bitmap_iterator bi;
1352 14504565 : bool eh_p = false;
1353 :
1354 35214444 : FOR_EACH_EDGE (e, ei, bb->succs)
1355 20709879 : if ((e->flags & EDGE_EH)
1356 20709879 : && IRA_BB_NODE (e->dest)->parent != IRA_BB_NODE (bb)->parent)
1357 : eh_p = true;
1358 :
1359 14504565 : if (! eh_p)
1360 14497201 : return;
1361 :
1362 96556 : EXECUTE_IF_SET_IN_BITMAP (df_get_live_out (bb), FIRST_PSEUDO_REGISTER, i, bi)
1363 : {
1364 89192 : ira_allocno_t a = ira_curr_regno_allocno_map[i];
1365 184891 : for (int n = ALLOCNO_NUM_OBJECTS (a) - 1; n >= 0; n--)
1366 : {
1367 95699 : ira_object_t obj = ALLOCNO_OBJECT (a, n);
1368 382796 : OBJECT_CONFLICT_HARD_REGS (obj) |= eh_return_data_regs;
1369 95699 : OBJECT_TOTAL_CONFLICT_HARD_REGS (obj) |= eh_return_data_regs;
1370 : }
1371 : }
1372 : }
1373 :
1374 : #endif
1375 :
1376 : /* Add conflicts for object OBJ from REGION landing pads using CALLEE_ABI. */
1377 : static void
1378 3558425 : add_conflict_from_region_landing_pads (eh_region region, ira_object_t obj,
1379 : function_abi callee_abi)
1380 : {
1381 3558425 : ira_allocno_t a = OBJECT_ALLOCNO (obj);
1382 3558425 : rtx_code_label *landing_label;
1383 3558425 : basic_block landing_bb;
1384 :
1385 7129259 : for (eh_landing_pad lp = region->landing_pads; lp ; lp = lp->next_lp)
1386 : {
1387 5950474 : if ((landing_label = lp->landing_pad) != NULL
1388 5950474 : && (landing_bb = BLOCK_FOR_INSN (landing_label)) != NULL
1389 11900897 : && (region->type != ERT_CLEANUP
1390 4454359 : || bitmap_bit_p (df_get_live_in (landing_bb),
1391 : ALLOCNO_REGNO (a))))
1392 : {
1393 2379640 : HARD_REG_SET new_conflict_regs
1394 2379640 : = callee_abi.mode_clobbers (ALLOCNO_MODE (a));
1395 9518560 : OBJECT_CONFLICT_HARD_REGS (obj) |= new_conflict_regs;
1396 2379640 : OBJECT_TOTAL_CONFLICT_HARD_REGS (obj) |= new_conflict_regs;
1397 2379640 : return;
1398 : }
1399 : }
1400 : }
1401 :
1402 : /* Process insns of the basic block given by its LOOP_TREE_NODE to
1403 : update allocno live ranges, allocno hard register conflicts,
1404 : intersected calls, and register pressure info for allocnos for the
1405 : basic block for and regions containing the basic block. */
1406 : static void
1407 16606336 : process_bb_node_lives (ira_loop_tree_node_t loop_tree_node)
1408 : {
1409 16606336 : int i, freq;
1410 16606336 : unsigned int j, k;
1411 16606336 : basic_block bb;
1412 16606336 : rtx_insn *insn;
1413 16606336 : bitmap_iterator bi;
1414 16606336 : bitmap reg_live_out;
1415 16606336 : unsigned int px;
1416 16606336 : bool set_p;
1417 :
1418 16606336 : bb = loop_tree_node->bb;
1419 16606336 : if (bb != NULL)
1420 : {
1421 71357330 : for (i = 0; i < ira_pressure_classes_num; i++)
1422 : {
1423 56852765 : curr_reg_pressure[ira_pressure_classes[i]] = 0;
1424 56852765 : high_pressure_start_point[ira_pressure_classes[i]] = -1;
1425 : }
1426 14504565 : curr_bb_node = loop_tree_node;
1427 14504565 : reg_live_out = df_get_live_out (bb);
1428 14504565 : sparseset_clear (objects_live);
1429 29009130 : REG_SET_TO_HARD_REG_SET (hard_regs_live, reg_live_out);
1430 14504565 : hard_regs_live &= ~(eliminable_regset | ira_no_alloc_regs);
1431 14504565 : hard_reg_set_iterator hrsi;
1432 14504565 : k = 0;
1433 15626102 : EXECUTE_IF_SET_IN_HARD_REG_SET (hard_regs_live, 0, k, hrsi)
1434 : {
1435 1121537 : enum reg_class aclass, pclass, cl;
1436 :
1437 1121537 : aclass = ira_allocno_class_translate[REGNO_REG_CLASS (k)];
1438 1121537 : pclass = ira_pressure_class_translate[aclass];
1439 10641460 : for (j = 0;
1440 10641460 : (cl = ira_reg_class_super_classes[pclass][j])
1441 10641460 : != LIM_REG_CLASSES;
1442 : j++)
1443 : {
1444 9519923 : if (! ira_reg_pressure_class_p[cl])
1445 8398386 : continue;
1446 1121537 : curr_reg_pressure[cl]++;
1447 1121537 : if (curr_bb_node->reg_pressure[cl] < curr_reg_pressure[cl])
1448 1121537 : curr_bb_node->reg_pressure[cl] = curr_reg_pressure[cl];
1449 1121537 : ira_assert (curr_reg_pressure[cl]
1450 : <= ira_class_hard_regs_num[cl]);
1451 : }
1452 : }
1453 154925536 : EXECUTE_IF_SET_IN_BITMAP (reg_live_out, FIRST_PSEUDO_REGISTER, j, bi)
1454 140420971 : mark_pseudo_regno_live (j);
1455 :
1456 : #ifdef EH_RETURN_DATA_REGNO
1457 14504565 : process_out_of_region_eh_regs (bb);
1458 : #endif
1459 :
1460 14504565 : freq = REG_FREQ_FROM_BB (bb);
1461 8622504 : if (freq == 0)
1462 2035934 : freq = 1;
1463 :
1464 : /* Invalidate all allocno_saved_at_call entries. */
1465 14504565 : last_call_num++;
1466 :
1467 : /* Scan the code of this basic block, noting which allocnos and
1468 : hard regs are born or die.
1469 :
1470 : Note that this loop treats uninitialized values as live until
1471 : the beginning of the block. For example, if an instruction
1472 : uses (reg:DI foo), and only (subreg:SI (reg:DI foo) 0) is ever
1473 : set, FOO will remain live until the beginning of the block.
1474 : Likewise if FOO is not set at all. This is unnecessarily
1475 : pessimistic, but it probably doesn't matter much in practice. */
1476 175976419 : FOR_BB_INSNS_REVERSE (bb, insn)
1477 : {
1478 161471854 : ira_allocno_t a;
1479 161471854 : df_ref def, use;
1480 161471854 : bool call_p;
1481 :
1482 161471854 : if (!NONDEBUG_INSN_P (insn))
1483 77335825 : continue;
1484 :
1485 84136029 : if (internal_flag_ira_verbose > 2 && ira_dump_file != NULL)
1486 1477 : fprintf (ira_dump_file, " Insn %u(l%d): point = %d\n",
1487 1477 : INSN_UID (insn), loop_tree_node->parent->loop_num,
1488 : curr_point);
1489 :
1490 84136029 : call_p = CALL_P (insn);
1491 84136029 : ignore_reg_for_conflicts = non_conflicting_reg_copy_p (insn);
1492 :
1493 : /* Mark each defined value as live. We need to do this for
1494 : unused values because they still conflict with quantities
1495 : that are live at the time of the definition.
1496 :
1497 : Ignore DF_REF_MAY_CLOBBERs on a call instruction. Such
1498 : references represent the effect of the called function
1499 : on a call-clobbered register. Marking the register as
1500 : live would stop us from allocating it to a call-crossing
1501 : allocno. */
1502 647916237 : FOR_EACH_INSN_DEF (def, insn)
1503 563780208 : if (!call_p || !DF_REF_FLAGS_IS_SET (def, DF_REF_MAY_CLOBBER))
1504 70573499 : mark_ref_live (def);
1505 :
1506 : /* If INSN has multiple outputs, then any value used in one
1507 : of the outputs conflicts with the other outputs. Model this
1508 : by making the used value live during the output phase.
1509 :
1510 : It is unsafe to use !single_set here since it will ignore
1511 : an unused output. Just because an output is unused does
1512 : not mean the compiler can assume the side effect will not
1513 : occur. Consider if ALLOCNO appears in the address of an
1514 : output and we reload the output. If we allocate ALLOCNO
1515 : to the same hard register as an unused output we could
1516 : set the hard register before the output reload insn. */
1517 84136029 : if (GET_CODE (PATTERN (insn)) == PARALLEL && multiple_sets (insn))
1518 1857464 : FOR_EACH_INSN_USE (use, insn)
1519 : {
1520 1462017 : int i;
1521 1462017 : rtx reg;
1522 :
1523 1462017 : reg = DF_REF_REG (use);
1524 4647910 : for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1525 : {
1526 3580419 : rtx set;
1527 :
1528 3580419 : set = XVECEXP (PATTERN (insn), 0, i);
1529 3580419 : if (GET_CODE (set) == SET
1530 3580419 : && reg_overlap_mentioned_p (reg, SET_DEST (set)))
1531 : {
1532 : /* After the previous loop, this is a no-op if
1533 : REG is contained within SET_DEST (SET). */
1534 394526 : mark_ref_live (use);
1535 394526 : break;
1536 : }
1537 : }
1538 : }
1539 :
1540 84136029 : preferred_alternatives = ira_setup_alts (insn);
1541 84136029 : process_register_constraint_filters ();
1542 84136029 : process_dependent_filters ();
1543 84136029 : process_single_reg_class_operands (false, freq);
1544 :
1545 84136029 : if (call_p)
1546 : {
1547 : /* Try to find a SET in the CALL_INSN_FUNCTION_USAGE, and from
1548 : there, try to find a pseudo that is live across the call but
1549 : can be cheaply reconstructed from the return value. */
1550 6052059 : rtx cheap_reg = find_call_crossed_cheap_reg (insn);
1551 6052059 : if (cheap_reg != NULL_RTX)
1552 33063 : add_reg_note (insn, REG_RETURNED, cheap_reg);
1553 :
1554 6052059 : last_call_num++;
1555 6052059 : sparseset_clear (allocnos_processed);
1556 : /* The current set of live allocnos are live across the call. */
1557 469770036 : EXECUTE_IF_SET_IN_SPARSESET (objects_live, i)
1558 : {
1559 228832959 : ira_object_t obj = ira_object_id_map[i];
1560 228832959 : a = OBJECT_ALLOCNO (obj);
1561 228832959 : int num = ALLOCNO_NUM (a);
1562 228832959 : function_abi callee_abi = insn_callee_abi (insn);
1563 :
1564 : /* Don't allocate allocnos that cross setjmps or any
1565 : call, if this function receives a nonlocal
1566 : goto. */
1567 228832959 : if (cfun->has_nonlocal_label
1568 228832959 : || (!targetm.setjmp_preserves_nonvolatile_regs_p ()
1569 228830390 : && (find_reg_note (insn, REG_SETJMP, NULL_RTX)
1570 : != NULL_RTX)))
1571 : {
1572 10974 : SET_HARD_REG_SET (OBJECT_CONFLICT_HARD_REGS (obj));
1573 228832959 : SET_HARD_REG_SET (OBJECT_TOTAL_CONFLICT_HARD_REGS (obj));
1574 : }
1575 228832959 : eh_region r;
1576 228832959 : if (can_throw_internal (insn)
1577 228832959 : && (r = get_eh_region_from_rtx (insn)) != NULL)
1578 3558425 : add_conflict_from_region_landing_pads (r, obj, callee_abi);
1579 228832959 : if (sparseset_bit_p (allocnos_processed, num))
1580 104001602 : continue;
1581 124831357 : sparseset_set_bit (allocnos_processed, num);
1582 :
1583 124831357 : if (allocno_saved_at_call[num] != last_call_num)
1584 : /* Here we are mimicking caller-save.cc behavior
1585 : which does not save hard register at a call if
1586 : it was saved on previous call in the same basic
1587 : block and the hard register was not mentioned
1588 : between the two calls. */
1589 39961106 : ALLOCNO_CALL_FREQ (a) += freq;
1590 : /* Mark it as saved at the next call. */
1591 124831357 : allocno_saved_at_call[num] = last_call_num + 1;
1592 124831357 : ALLOCNO_CALLS_CROSSED_NUM (a)++;
1593 124831357 : ALLOCNO_CROSSED_CALLS_ABIS (a) |= 1 << callee_abi.id ();
1594 124831357 : ALLOCNO_CROSSED_CALLS_CLOBBERED_REGS (a)
1595 124831357 : |= callee_abi.full_and_partial_reg_clobbers ();
1596 124831357 : if (cheap_reg != NULL_RTX
1597 124831357 : && ALLOCNO_REGNO (a) == (int) REGNO (cheap_reg))
1598 33063 : ALLOCNO_CHEAP_CALLS_CROSSED_NUM (a)++;
1599 : }
1600 : }
1601 :
1602 : /* See which defined values die here. Note that we include
1603 : the call insn in the lifetimes of these values, so we don't
1604 : mistakenly consider, for e.g. an addressing mode with a
1605 : side-effect like a post-increment fetching the address,
1606 : that the use happens before the call, and the def to happen
1607 : after the call: we believe both to happen before the actual
1608 : call. (We don't handle return-values here.) */
1609 647916237 : FOR_EACH_INSN_DEF (def, insn)
1610 563780208 : if (!call_p || !DF_REF_FLAGS_IS_SET (def, DF_REF_MAY_CLOBBER))
1611 70573499 : mark_ref_dead (def);
1612 :
1613 84136029 : make_early_clobber_and_input_conflicts ();
1614 :
1615 84136029 : curr_point++;
1616 :
1617 : /* Mark each used value as live. */
1618 185656847 : FOR_EACH_INSN_USE (use, insn)
1619 101520818 : mark_ref_live (use);
1620 :
1621 84136029 : process_single_reg_class_operands (true, freq);
1622 :
1623 84136029 : set_p = mark_hard_reg_early_clobbers (insn, true);
1624 :
1625 84136029 : if (set_p)
1626 : {
1627 10672769 : mark_hard_reg_early_clobbers (insn, false);
1628 :
1629 : /* Mark each hard reg as live again. For example, a
1630 : hard register can be in clobber and in an insn
1631 : input. */
1632 26118825 : FOR_EACH_INSN_USE (use, insn)
1633 : {
1634 15446056 : rtx ureg = DF_REF_REG (use);
1635 :
1636 15446056 : if (GET_CODE (ureg) == SUBREG)
1637 327826 : ureg = SUBREG_REG (ureg);
1638 15446056 : if (! REG_P (ureg) || REGNO (ureg) >= FIRST_PSEUDO_REGISTER)
1639 9833498 : continue;
1640 :
1641 5612558 : mark_ref_live (use);
1642 : }
1643 : }
1644 :
1645 84136029 : curr_point++;
1646 : }
1647 14504565 : ignore_reg_for_conflicts = NULL_RTX;
1648 :
1649 14504565 : if (bb_has_eh_pred (bb))
1650 216903 : for (j = 0; ; ++j)
1651 : {
1652 650709 : unsigned int regno = EH_RETURN_DATA_REGNO (j);
1653 433806 : if (regno == INVALID_REGNUM)
1654 : break;
1655 433806 : make_hard_regno_live (regno);
1656 433806 : }
1657 :
1658 : /* Allocnos can't go in stack regs at the start of a basic block
1659 : that is reached by an abnormal edge. Likewise for registers
1660 : that are at least partly call clobbered, because caller-save,
1661 : fixup_abnormal_edges and possibly the table driven EH machinery
1662 : are not quite ready to handle such allocnos live across such
1663 : edges. */
1664 14504565 : if (bb_has_abnormal_pred (bb))
1665 : {
1666 : #ifdef STACK_REGS
1667 684201 : EXECUTE_IF_SET_IN_SPARSESET (objects_live, px)
1668 : {
1669 464857 : ira_allocno_t a = OBJECT_ALLOCNO (ira_object_id_map[px]);
1670 :
1671 464857 : ALLOCNO_NO_STACK_REG_P (a) = true;
1672 464857 : ALLOCNO_TOTAL_NO_STACK_REG_P (a) = true;
1673 : }
1674 1974096 : for (px = FIRST_STACK_REG; px <= LAST_STACK_REG; px++)
1675 1754752 : make_hard_regno_live (px);
1676 : #endif
1677 : /* No need to record conflicts for call clobbered regs if we
1678 : have nonlocal labels around, as we don't ever try to
1679 : allocate such regs in this case. */
1680 219344 : if (!cfun->has_nonlocal_label
1681 219344 : && has_abnormal_call_or_eh_pred_edge_p (bb))
1682 20171142 : for (px = 0; px < FIRST_PSEUDO_REGISTER; px++)
1683 19954248 : if (eh_edge_abi.clobbers_at_least_part_of_reg_p (px)
1684 : #ifdef REAL_PIC_OFFSET_TABLE_REGNUM
1685 : /* We should create a conflict of PIC pseudo with
1686 : PIC hard reg as PIC hard reg can have a wrong
1687 : value after jump described by the abnormal edge.
1688 : In this case we cannot allocate PIC hard reg to
1689 : PIC pseudo as PIC pseudo will also have a wrong
1690 : value. This code is not critical as LRA can fix
1691 : it but it is better to have the right allocation
1692 : earlier. */
1693 20093583 : || (px == REAL_PIC_OFFSET_TABLE_REGNUM
1694 216894 : && pic_offset_table_rtx != NULL_RTX
1695 6301 : && REGNO (pic_offset_table_rtx) >= FIRST_PSEUDO_REGISTER)
1696 : #endif
1697 : )
1698 18048313 : make_hard_regno_live (px);
1699 : }
1700 :
1701 219441384 : EXECUTE_IF_SET_IN_SPARSESET (objects_live, i)
1702 204936819 : make_object_dead (ira_object_id_map[i]);
1703 :
1704 14504565 : curr_point++;
1705 :
1706 : }
1707 : /* Propagate register pressure to upper loop tree nodes. */
1708 16606336 : if (loop_tree_node != ira_loop_tree_root)
1709 74404772 : for (i = 0; i < ira_pressure_classes_num; i++)
1710 : {
1711 59292376 : enum reg_class pclass;
1712 :
1713 59292376 : pclass = ira_pressure_classes[i];
1714 59292376 : if (loop_tree_node->reg_pressure[pclass]
1715 59292376 : > loop_tree_node->parent->reg_pressure[pclass])
1716 4221302 : loop_tree_node->parent->reg_pressure[pclass]
1717 4221302 : = loop_tree_node->reg_pressure[pclass];
1718 : }
1719 16606336 : }
1720 :
1721 : /* Create and set up IRA_START_POINT_RANGES and
1722 : IRA_FINISH_POINT_RANGES. */
1723 : static void
1724 3147693 : create_start_finish_chains (void)
1725 : {
1726 3147693 : ira_object_t obj;
1727 3147693 : ira_object_iterator oi;
1728 3147693 : live_range_t r;
1729 :
1730 3147693 : ira_start_point_ranges
1731 3147693 : = (live_range_t *) ira_allocate (ira_max_point * sizeof (live_range_t));
1732 3147693 : memset (ira_start_point_ranges, 0, ira_max_point * sizeof (live_range_t));
1733 3147693 : ira_finish_point_ranges
1734 3147693 : = (live_range_t *) ira_allocate (ira_max_point * sizeof (live_range_t));
1735 3147693 : memset (ira_finish_point_ranges, 0, ira_max_point * sizeof (live_range_t));
1736 80864668 : FOR_EACH_OBJECT (obj, oi)
1737 183725542 : for (r = OBJECT_LIVE_RANGES (obj); r != NULL; r = r->next)
1738 : {
1739 106008567 : r->start_next = ira_start_point_ranges[r->start];
1740 106008567 : ira_start_point_ranges[r->start] = r;
1741 106008567 : r->finish_next = ira_finish_point_ranges[r->finish];
1742 106008567 : ira_finish_point_ranges[r->finish] = r;
1743 : }
1744 3147693 : }
1745 :
1746 : /* Rebuild IRA_START_POINT_RANGES and IRA_FINISH_POINT_RANGES after
1747 : new live ranges and program points were added as a result if new
1748 : insn generation. */
1749 : void
1750 1653753 : ira_rebuild_start_finish_chains (void)
1751 : {
1752 1653753 : ira_free (ira_finish_point_ranges);
1753 1653753 : ira_free (ira_start_point_ranges);
1754 1653753 : create_start_finish_chains ();
1755 1653753 : }
1756 :
1757 : /* Compress allocno live ranges by removing program points where
1758 : nothing happens. */
1759 : static void
1760 1493940 : remove_some_program_points_and_update_live_ranges (void)
1761 : {
1762 1493940 : unsigned i;
1763 1493940 : int n;
1764 1493940 : int *map;
1765 1493940 : ira_object_t obj;
1766 1493940 : ira_object_iterator oi;
1767 1493940 : live_range_t r, prev_r, next_r;
1768 1493940 : sbitmap_iterator sbi;
1769 1493940 : bool born_p, dead_p, prev_born_p, prev_dead_p;
1770 :
1771 1493940 : auto_sbitmap born (ira_max_point);
1772 1493940 : auto_sbitmap dead (ira_max_point);
1773 1493940 : bitmap_clear (born);
1774 1493940 : bitmap_clear (dead);
1775 35876874 : FOR_EACH_OBJECT (obj, oi)
1776 88031423 : for (r = OBJECT_LIVE_RANGES (obj); r != NULL; r = r->next)
1777 : {
1778 53648489 : ira_assert (r->start <= r->finish);
1779 53648489 : bitmap_set_bit (born, r->start);
1780 53648489 : bitmap_set_bit (dead, r->finish);
1781 : }
1782 :
1783 1493940 : auto_sbitmap born_or_dead (ira_max_point);
1784 1493940 : bitmap_ior (born_or_dead, born, dead);
1785 1493940 : map = (int *) ira_allocate (sizeof (int) * ira_max_point);
1786 1493940 : n = -1;
1787 1493940 : prev_born_p = prev_dead_p = false;
1788 67162725 : EXECUTE_IF_SET_IN_BITMAP (born_or_dead, 0, i, sbi)
1789 : {
1790 64174845 : born_p = bitmap_bit_p (born, i);
1791 64174845 : dead_p = bitmap_bit_p (dead, i);
1792 64174845 : if ((prev_born_p && ! prev_dead_p && born_p && ! dead_p)
1793 58058732 : || (prev_dead_p && ! prev_born_p && dead_p && ! born_p))
1794 16152395 : map[i] = n;
1795 : else
1796 48022450 : map[i] = ++n;
1797 64174845 : prev_born_p = born_p;
1798 64174845 : prev_dead_p = dead_p;
1799 : }
1800 :
1801 1493940 : n++;
1802 1493940 : if (internal_flag_ira_verbose > 1 && ira_dump_file != NULL)
1803 95 : fprintf (ira_dump_file, "Compressing live ranges: from %d to %d - %d%%\n",
1804 95 : ira_max_point, n, 100 * n / ira_max_point);
1805 1493940 : ira_max_point = n;
1806 :
1807 35876874 : FOR_EACH_OBJECT (obj, oi)
1808 88031423 : for (r = OBJECT_LIVE_RANGES (obj), prev_r = NULL; r != NULL; r = next_r)
1809 : {
1810 53648489 : next_r = r->next;
1811 53648489 : r->start = map[r->start];
1812 53648489 : r->finish = map[r->finish];
1813 53648489 : if (prev_r == NULL || prev_r->start > r->finish + 1)
1814 : {
1815 41010036 : prev_r = r;
1816 41010036 : continue;
1817 : }
1818 12638453 : prev_r->start = r->start;
1819 12638453 : prev_r->next = next_r;
1820 12638453 : ira_finish_live_range (r);
1821 : }
1822 :
1823 1493940 : ira_free (map);
1824 1493940 : }
1825 :
1826 : /* Print live ranges R to file F. */
1827 : void
1828 1466 : ira_print_live_range_list (FILE *f, live_range_t r)
1829 : {
1830 3234 : for (; r != NULL; r = r->next)
1831 1768 : fprintf (f, " [%d..%d]", r->start, r->finish);
1832 1466 : fprintf (f, "\n");
1833 1466 : }
1834 :
1835 : DEBUG_FUNCTION void
1836 0 : debug (live_range &ref)
1837 : {
1838 0 : ira_print_live_range_list (stderr, &ref);
1839 0 : }
1840 :
1841 : DEBUG_FUNCTION void
1842 0 : debug (live_range *ptr)
1843 : {
1844 0 : if (ptr)
1845 0 : debug (*ptr);
1846 : else
1847 0 : fprintf (stderr, "<nil>\n");
1848 0 : }
1849 :
1850 : /* Print live ranges R to stderr. */
1851 : void
1852 0 : ira_debug_live_range_list (live_range_t r)
1853 : {
1854 0 : ira_print_live_range_list (stderr, r);
1855 0 : }
1856 :
1857 : /* Print live ranges of object OBJ to file F. */
1858 : static void
1859 1328 : print_object_live_ranges (FILE *f, ira_object_t obj)
1860 : {
1861 0 : ira_print_live_range_list (f, OBJECT_LIVE_RANGES (obj));
1862 0 : }
1863 :
1864 : /* Print live ranges of allocno A to file F. */
1865 : static void
1866 1328 : print_allocno_live_ranges (FILE *f, ira_allocno_t a)
1867 : {
1868 1328 : int n = ALLOCNO_NUM_OBJECTS (a);
1869 1328 : int i;
1870 :
1871 2656 : for (i = 0; i < n; i++)
1872 : {
1873 1328 : fprintf (f, " a%d(r%d", ALLOCNO_NUM (a), ALLOCNO_REGNO (a));
1874 1328 : if (n > 1)
1875 0 : fprintf (f, " [%d]", i);
1876 1328 : fprintf (f, "):");
1877 1328 : print_object_live_ranges (f, ALLOCNO_OBJECT (a, i));
1878 : }
1879 1328 : }
1880 :
1881 : /* Print live ranges of allocno A to stderr. */
1882 : void
1883 0 : ira_debug_allocno_live_ranges (ira_allocno_t a)
1884 : {
1885 0 : print_allocno_live_ranges (stderr, a);
1886 0 : }
1887 :
1888 : /* Print live ranges of all allocnos to file F. */
1889 : static void
1890 190 : print_live_ranges (FILE *f)
1891 : {
1892 190 : ira_allocno_t a;
1893 190 : ira_allocno_iterator ai;
1894 :
1895 1518 : FOR_EACH_ALLOCNO (a, ai)
1896 1328 : print_allocno_live_ranges (f, a);
1897 190 : }
1898 :
1899 : /* Print live ranges of all allocnos to stderr. */
1900 : void
1901 0 : ira_debug_live_ranges (void)
1902 : {
1903 0 : print_live_ranges (stderr);
1904 0 : }
1905 :
1906 : /* The main entry function creates live ranges, set up
1907 : CONFLICT_HARD_REGS and TOTAL_CONFLICT_HARD_REGS for objects, and
1908 : calculate register pressure info. */
1909 : void
1910 1493940 : ira_create_allocno_live_ranges (void)
1911 : {
1912 1493940 : objects_live = sparseset_alloc (ira_objects_num);
1913 1493940 : allocnos_processed = sparseset_alloc (ira_allocnos_num);
1914 1493940 : curr_point = 0;
1915 1493940 : last_call_num = 0;
1916 1493940 : allocno_saved_at_call
1917 1493940 : = (int *) ira_allocate (ira_allocnos_num * sizeof (int));
1918 1493940 : memset (allocno_saved_at_call, 0, ira_allocnos_num * sizeof (int));
1919 1493940 : ira_traverse_loop_tree (true, ira_loop_tree_root, NULL,
1920 : process_bb_node_lives);
1921 1493940 : ira_max_point = curr_point;
1922 1493940 : create_start_finish_chains ();
1923 1493940 : if (internal_flag_ira_verbose > 2 && ira_dump_file != NULL)
1924 95 : print_live_ranges (ira_dump_file);
1925 : /* Clean up. */
1926 1493940 : ira_free (allocno_saved_at_call);
1927 1493940 : sparseset_free (objects_live);
1928 1493940 : sparseset_free (allocnos_processed);
1929 1493940 : }
1930 :
1931 : /* Compress allocno live ranges. */
1932 : void
1933 1493940 : ira_compress_allocno_live_ranges (void)
1934 : {
1935 1493940 : remove_some_program_points_and_update_live_ranges ();
1936 1493940 : ira_rebuild_start_finish_chains ();
1937 1493940 : if (internal_flag_ira_verbose > 2 && ira_dump_file != NULL)
1938 : {
1939 95 : fprintf (ira_dump_file, "Ranges after the compression:\n");
1940 95 : print_live_ranges (ira_dump_file);
1941 : }
1942 1493940 : }
1943 :
1944 : /* Free arrays IRA_START_POINT_RANGES and IRA_FINISH_POINT_RANGES. */
1945 : void
1946 1493940 : ira_finish_allocno_live_ranges (void)
1947 : {
1948 1493940 : ira_free (ira_finish_point_ranges);
1949 1493940 : ira_free (ira_start_point_ranges);
1950 1493940 : }
|