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 38651254 : make_hard_regno_live (int regno)
98 : {
99 38651254 : SET_HARD_REG_BIT (hard_regs_live, regno);
100 0 : }
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 15312478 : make_hard_regno_dead (int regno)
106 : {
107 15312478 : unsigned int i;
108 280977758 : EXECUTE_IF_SET_IN_SPARSESET (objects_live, i)
109 : {
110 265665280 : ira_object_t obj = ira_object_id_map[i];
111 :
112 267382531 : if (ignore_reg_for_conflicts != NULL_RTX
113 174436988 : && REGNO (ignore_reg_for_conflicts)
114 174436988 : == (unsigned int) ALLOCNO_REGNO (OBJECT_ALLOCNO (obj)))
115 1717251 : continue;
116 :
117 263948029 : SET_HARD_REG_BIT (OBJECT_CONFLICT_HARD_REGS (obj), regno);
118 263948029 : SET_HARD_REG_BIT (OBJECT_TOTAL_CONFLICT_HARD_REGS (obj), regno);
119 : }
120 15312478 : CLEAR_HARD_REG_BIT (hard_regs_live, regno);
121 15312478 : }
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 243908412 : make_object_live (ira_object_t obj)
127 : {
128 243908412 : sparseset_set_bit (objects_live, OBJECT_CONFLICT_ID (obj));
129 :
130 243908412 : live_range_t lr = OBJECT_LIVE_RANGES (obj);
131 243908412 : if (lr == NULL
132 206335228 : || (lr->finish != curr_point && lr->finish + 1 != curr_point))
133 55564355 : ira_add_live_range_to_object (obj, curr_point, -1);
134 243908412 : }
135 :
136 : /* Update ALLOCNO_EXCESS_PRESSURE_POINTS_NUM for the allocno
137 : associated with object OBJ. */
138 : static void
139 251495464 : update_allocno_pressure_excess_length (ira_object_t obj)
140 : {
141 251495464 : ira_allocno_t a = OBJECT_ALLOCNO (obj);
142 251495464 : int start, i;
143 251495464 : enum reg_class aclass, pclass, cl;
144 251495464 : live_range_t p;
145 :
146 251495464 : aclass = ALLOCNO_CLASS (a);
147 251495464 : pclass = ira_pressure_class_translate[aclass];
148 2469843196 : for (i = 0;
149 2469843196 : (cl = ira_reg_class_super_classes[pclass][i]) != LIM_REG_CLASSES;
150 : i++)
151 : {
152 2218347732 : if (! ira_reg_pressure_class_p[cl])
153 1971837979 : continue;
154 246509753 : if (high_pressure_start_point[cl] < 0)
155 75675553 : continue;
156 170834200 : p = OBJECT_LIVE_RANGES (obj);
157 170834200 : ira_assert (p != NULL);
158 170834200 : start = (high_pressure_start_point[cl] > p->start
159 170834200 : ? high_pressure_start_point[cl] : p->start);
160 170834200 : ALLOCNO_EXCESS_PRESSURE_POINTS_NUM (a) += curr_point - start + 1;
161 : }
162 251495464 : }
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 243908412 : make_object_dead (ira_object_t obj)
168 : {
169 243908412 : live_range_t lr;
170 243908412 : int regno;
171 243908412 : int ignore_regno = -1;
172 243908412 : int ignore_total_regno = -1;
173 243908412 : int end_regno = -1;
174 :
175 243908412 : 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 243908412 : if (ignore_reg_for_conflicts != NULL_RTX
180 243908412 : && REGNO (ignore_reg_for_conflicts) < FIRST_PSEUDO_REGISTER)
181 : {
182 3496664 : end_regno = END_REGNO (ignore_reg_for_conflicts);
183 3496664 : ignore_regno = ignore_total_regno = REGNO (ignore_reg_for_conflicts);
184 :
185 6993328 : for (regno = ignore_regno; regno < end_regno; regno++)
186 : {
187 3496664 : if (TEST_HARD_REG_BIT (OBJECT_CONFLICT_HARD_REGS (obj), regno))
188 521870 : ignore_regno = end_regno;
189 3496664 : if (TEST_HARD_REG_BIT (OBJECT_TOTAL_CONFLICT_HARD_REGS (obj), regno))
190 521870 : ignore_total_regno = end_regno;
191 : }
192 : }
193 :
194 975633648 : OBJECT_CONFLICT_HARD_REGS (obj) |= hard_regs_live;
195 246883206 : 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 246883206 : for (regno = ignore_regno; regno < end_regno; regno++)
200 2974794 : CLEAR_HARD_REG_BIT (OBJECT_CONFLICT_HARD_REGS (obj), regno);
201 246883206 : for (regno = ignore_total_regno; regno < end_regno; regno++)
202 2974794 : CLEAR_HARD_REG_BIT (OBJECT_TOTAL_CONFLICT_HARD_REGS (obj), regno);
203 :
204 243908412 : lr = OBJECT_LIVE_RANGES (obj);
205 243908412 : ira_assert (lr != NULL);
206 243908412 : lr->finish = curr_point;
207 243908412 : update_allocno_pressure_excess_length (obj);
208 243908412 : }
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 260825877 : inc_register_pressure (enum reg_class pclass, int n)
220 : {
221 260825877 : int i;
222 260825877 : enum reg_class cl;
223 :
224 2560360920 : for (i = 0;
225 2560360920 : (cl = ira_reg_class_super_classes[pclass][i]) != LIM_REG_CLASSES;
226 : i++)
227 : {
228 2299535043 : if (! ira_reg_pressure_class_p[cl])
229 2043442731 : continue;
230 256092312 : curr_reg_pressure[cl] += n;
231 256092312 : if (high_pressure_start_point[cl] < 0
232 107016979 : && (curr_reg_pressure[cl] > ira_class_hard_regs_num[cl]))
233 1763918 : high_pressure_start_point[cl] = curr_point;
234 256092312 : if (curr_bb_node->reg_pressure[cl] < curr_reg_pressure[cl])
235 220684937 : curr_bb_node->reg_pressure[cl] = curr_reg_pressure[cl];
236 : }
237 260825877 : }
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 53537377 : dec_register_pressure (enum reg_class pclass, int nregs)
246 : {
247 53537377 : int i;
248 53537377 : unsigned int j;
249 53537377 : enum reg_class cl;
250 53537377 : bool set_p = false;
251 :
252 53537377 : for (i = 0;
253 519719208 : (cl = ira_reg_class_super_classes[pclass][i]) != LIM_REG_CLASSES;
254 : i++)
255 : {
256 466181831 : if (! ira_reg_pressure_class_p[cl])
257 413146390 : continue;
258 53035441 : curr_reg_pressure[cl] -= nregs;
259 53035441 : ira_assert (curr_reg_pressure[cl] >= 0);
260 53035441 : if (high_pressure_start_point[cl] >= 0
261 4747433 : && curr_reg_pressure[cl] <= ira_class_hard_regs_num[cl])
262 466181831 : set_p = true;
263 : }
264 53537377 : if (set_p)
265 : {
266 8079364 : EXECUTE_IF_SET_IN_SPARSESET (objects_live, j)
267 7587052 : update_allocno_pressure_excess_length (ira_object_id_map[j]);
268 4677995 : for (i = 0;
269 5170307 : (cl = ira_reg_class_super_classes[pclass][i]) != LIM_REG_CLASSES;
270 : i++)
271 : {
272 4677995 : if (! ira_reg_pressure_class_p[cl])
273 4185683 : continue;
274 492312 : if (high_pressure_start_point[cl] >= 0
275 492312 : && curr_reg_pressure[cl] <= ira_class_hard_regs_num[cl])
276 492312 : high_pressure_start_point[cl] = -1;
277 : }
278 : }
279 53537377 : }
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 121837 : pseudo_regno_single_word_and_live_p (int regno)
285 : {
286 121837 : ira_allocno_t a = ira_curr_regno_allocno_map[regno];
287 121837 : ira_object_t obj;
288 :
289 121837 : if (a == NULL)
290 : return false;
291 121837 : if (ALLOCNO_NUM_OBJECTS (a) > 1)
292 : return false;
293 :
294 121837 : obj = ALLOCNO_OBJECT (a, 0);
295 :
296 121837 : 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 229544865 : mark_pseudo_regno_live (int regno)
303 : {
304 229544865 : ira_allocno_t a = ira_curr_regno_allocno_map[regno];
305 229544865 : enum reg_class pclass;
306 229544865 : int i, n, nregs;
307 :
308 229544865 : if (a == NULL)
309 : return;
310 :
311 : /* Invalidate because it is referenced. */
312 229544865 : allocno_saved_at_call[ALLOCNO_NUM (a)] = 0;
313 :
314 229544865 : n = ALLOCNO_NUM_OBJECTS (a);
315 229544865 : pclass = ira_pressure_class_translate[ALLOCNO_CLASS (a)];
316 229544865 : nregs = ira_reg_class_max_nregs[ALLOCNO_CLASS (a)][ALLOCNO_MODE (a)];
317 229544865 : if (n > 1)
318 : {
319 : /* We track every subobject separately. */
320 69951222 : gcc_assert (nregs == n);
321 : nregs = 1;
322 : }
323 :
324 529040952 : for (i = 0; i < n; i++)
325 : {
326 299496087 : ira_object_t obj = ALLOCNO_OBJECT (a, i);
327 :
328 299496087 : if (sparseset_bit_p (objects_live, OBJECT_CONFLICT_ID (obj)))
329 55920267 : continue;
330 :
331 243575820 : inc_register_pressure (pclass, nregs);
332 243575820 : 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 875214 : mark_pseudo_regno_subword_live (int regno, int subword)
341 : {
342 875214 : ira_allocno_t a = ira_curr_regno_allocno_map[regno];
343 875214 : int n;
344 875214 : enum reg_class pclass;
345 875214 : ira_object_t obj;
346 :
347 875214 : if (a == NULL)
348 : return;
349 :
350 : /* Invalidate because it is referenced. */
351 875214 : allocno_saved_at_call[ALLOCNO_NUM (a)] = 0;
352 :
353 875214 : n = ALLOCNO_NUM_OBJECTS (a);
354 875214 : if (n == 1)
355 : {
356 39656 : mark_pseudo_regno_live (regno);
357 39656 : return;
358 : }
359 :
360 835558 : pclass = ira_pressure_class_translate[ALLOCNO_CLASS (a)];
361 835558 : gcc_assert
362 : (n == ira_reg_class_max_nregs[ALLOCNO_CLASS (a)][ALLOCNO_MODE (a)]);
363 835558 : obj = ALLOCNO_OBJECT (a, subword);
364 :
365 835558 : if (sparseset_bit_p (objects_live, OBJECT_CONFLICT_ID (obj)))
366 : return;
367 :
368 332592 : inc_register_pressure (pclass, 1);
369 332592 : 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 104785347 : mark_hard_reg_live (rtx reg)
377 : {
378 104785347 : int regno = REGNO (reg);
379 :
380 104785347 : if (! TEST_HARD_REG_BIT (ira_no_alloc_regs, regno))
381 : {
382 31959830 : int last = END_REGNO (reg);
383 31959830 : enum reg_class aclass, pclass;
384 :
385 63919660 : while (regno < last)
386 : {
387 31959830 : if (! TEST_HARD_REG_BIT (hard_regs_live, regno)
388 31959830 : && ! TEST_HARD_REG_BIT (eliminable_regset, regno))
389 : {
390 16917465 : aclass = ira_hard_regno_allocno_class[regno];
391 16917465 : pclass = ira_pressure_class_translate[aclass];
392 16917465 : inc_register_pressure (pclass, 1);
393 16917465 : make_hard_regno_live (regno);
394 : }
395 31959830 : regno++;
396 : }
397 : }
398 104785347 : }
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 89133278 : mark_pseudo_reg_live (rtx orig_reg, unsigned regno)
405 : {
406 89133278 : if (read_modify_subreg_p (orig_reg))
407 : {
408 1306485 : mark_pseudo_regno_subword_live (regno,
409 875214 : subreg_lowpart_p (orig_reg) ? 0 : 1);
410 : }
411 : else
412 88258064 : mark_pseudo_regno_live (regno);
413 89133278 : }
414 :
415 : /* Mark the register referenced by use or def REF as live. */
416 : static void
417 192046935 : mark_ref_live (df_ref ref)
418 : {
419 192046935 : rtx reg = DF_REF_REG (ref);
420 192046935 : rtx orig_reg = reg;
421 :
422 192046935 : if (GET_CODE (reg) == SUBREG)
423 3088489 : reg = SUBREG_REG (reg);
424 :
425 192046935 : if (REGNO (reg) >= FIRST_PSEUDO_REGISTER)
426 87261588 : mark_pseudo_reg_live (orig_reg, REGNO (reg));
427 : else
428 104785347 : mark_hard_reg_live (reg);
429 192046935 : }
430 :
431 : /* Mark the pseudo register REGNO as dead. Update all information about
432 : live ranges and register pressure. */
433 : static void
434 36568927 : mark_pseudo_regno_dead (int regno)
435 : {
436 36568927 : ira_allocno_t a = ira_curr_regno_allocno_map[regno];
437 36568927 : int n, i, nregs;
438 36568927 : enum reg_class cl;
439 :
440 36568927 : if (a == NULL)
441 : return;
442 :
443 : /* Invalidate because it is referenced. */
444 36568927 : allocno_saved_at_call[ALLOCNO_NUM (a)] = 0;
445 :
446 36568927 : n = ALLOCNO_NUM_OBJECTS (a);
447 36568927 : cl = ira_pressure_class_translate[ALLOCNO_CLASS (a)];
448 36568927 : nregs = ira_reg_class_max_nregs[ALLOCNO_CLASS (a)][ALLOCNO_MODE (a)];
449 36568927 : if (n > 1)
450 : {
451 : /* We track every subobject separately. */
452 1318756 : gcc_assert (nregs == n);
453 : nregs = 1;
454 : }
455 74456610 : for (i = 0; i < n; i++)
456 : {
457 37887683 : ira_object_t obj = ALLOCNO_OBJECT (a, i);
458 37887683 : if (!sparseset_bit_p (objects_live, OBJECT_CONFLICT_ID (obj)))
459 3653 : continue;
460 :
461 37884030 : dec_register_pressure (cl, nregs);
462 37884030 : 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 345269 : mark_pseudo_regno_subword_dead (int regno, int subword)
470 : {
471 345269 : ira_allocno_t a = ira_curr_regno_allocno_map[regno];
472 345269 : int n;
473 345269 : enum reg_class cl;
474 345269 : ira_object_t obj;
475 :
476 345269 : if (a == NULL)
477 : return;
478 :
479 : /* Invalidate because it is referenced. */
480 345269 : allocno_saved_at_call[ALLOCNO_NUM (a)] = 0;
481 :
482 345269 : n = ALLOCNO_NUM_OBJECTS (a);
483 345269 : if (n == 1)
484 : /* The allocno as a whole doesn't die in this case. */
485 : return;
486 :
487 340869 : cl = ira_pressure_class_translate[ALLOCNO_CLASS (a)];
488 340869 : gcc_assert
489 : (n == ira_reg_class_max_nregs[ALLOCNO_CLASS (a)][ALLOCNO_MODE (a)]);
490 :
491 340869 : obj = ALLOCNO_OBJECT (a, subword);
492 340869 : if (!sparseset_bit_p (objects_live, OBJECT_CONFLICT_ID (obj)))
493 : return;
494 :
495 340869 : dec_register_pressure (cl, 1);
496 340869 : 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 47714597 : mark_hard_reg_dead (rtx reg)
503 : {
504 47714597 : int regno = REGNO (reg);
505 :
506 47714597 : if (! TEST_HARD_REG_BIT (ira_no_alloc_regs, regno))
507 : {
508 15314529 : int last = END_REGNO (reg);
509 15314529 : enum reg_class aclass, pclass;
510 :
511 30629058 : while (regno < last)
512 : {
513 15314529 : if (TEST_HARD_REG_BIT (hard_regs_live, regno))
514 : {
515 15312478 : aclass = ira_hard_regno_allocno_class[regno];
516 15312478 : pclass = ira_pressure_class_translate[aclass];
517 15312478 : dec_register_pressure (pclass, 1);
518 15312478 : make_hard_regno_dead (regno);
519 : }
520 15314529 : regno++;
521 : }
522 : }
523 47714597 : }
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 36914196 : mark_pseudo_reg_dead (rtx orig_reg, unsigned regno)
530 : {
531 36914196 : if (read_modify_subreg_p (orig_reg))
532 : {
533 519462 : mark_pseudo_regno_subword_dead (regno,
534 345269 : subreg_lowpart_p (orig_reg) ? 0 : 1);
535 : }
536 : else
537 36568927 : mark_pseudo_regno_dead (regno);
538 36914196 : }
539 :
540 : /* Mark the register referenced by definition DEF as dead, if the
541 : definition is a total one. */
542 : static void
543 82761406 : mark_ref_dead (df_ref def)
544 : {
545 82761406 : rtx reg = DF_REF_REG (def);
546 82761406 : rtx orig_reg = reg;
547 :
548 82761406 : if (DF_REF_FLAGS_IS_SET (def, DF_REF_CONDITIONAL))
549 : return;
550 :
551 82761406 : if (GET_CODE (reg) == SUBREG)
552 922037 : reg = SUBREG_REG (reg);
553 :
554 82761406 : if (DF_REF_FLAGS_IS_SET (def, DF_REF_PARTIAL)
555 82761406 : && (GET_CODE (orig_reg) != SUBREG
556 333592 : || REGNO (reg) < FIRST_PSEUDO_REGISTER
557 333592 : || !read_modify_subreg_p (orig_reg)))
558 : return;
559 :
560 82757103 : if (REGNO (reg) >= FIRST_PSEUDO_REGISTER)
561 35042506 : mark_pseudo_reg_dead (orig_reg, REGNO (reg));
562 : else
563 47714597 : 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 2966176 : make_pseudo_conflict (rtx reg, enum reg_class cl, rtx dreg, rtx orig_dreg,
574 : bool advance_p)
575 : {
576 2966176 : rtx orig_reg = reg;
577 2966176 : ira_allocno_t a;
578 :
579 2966176 : if (GET_CODE (reg) == SUBREG)
580 85284 : reg = SUBREG_REG (reg);
581 :
582 2966176 : if (! REG_P (reg) || REGNO (reg) < FIRST_PSEUDO_REGISTER)
583 : return advance_p;
584 :
585 1011336 : a = ira_curr_regno_allocno_map[REGNO (reg)];
586 1011336 : if (! reg_classes_intersect_p (cl, ALLOCNO_CLASS (a)))
587 : return advance_p;
588 :
589 935845 : if (advance_p)
590 890832 : curr_point++;
591 :
592 935845 : mark_pseudo_reg_live (orig_reg, REGNO (reg));
593 935845 : mark_pseudo_reg_live (orig_dreg, REGNO (dreg));
594 935845 : mark_pseudo_reg_dead (orig_reg, REGNO (reg));
595 935845 : mark_pseudo_reg_dead (orig_dreg, REGNO (dreg));
596 :
597 935845 : 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 3016055 : 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 3016055 : if (! reg_classes_intersect_p (def_cl, use_cl))
612 : return advance_p;
613 :
614 2950621 : 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 2950621 : if (use < recog_data.n_operands - 1
624 1180186 : && recog_data.constraints[use][0] == '%')
625 6485 : advance_p
626 6485 : = make_pseudo_conflict (recog_data.operand[use + 1],
627 : use_cl, dreg, orig_dreg, advance_p);
628 2950621 : if (use >= 1
629 2950326 : && recog_data.constraints[use - 1][0] == '%')
630 9070 : advance_p
631 9070 : = 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 14720840 : check_and_make_def_conflict (int alt, int def, enum reg_class def_cl,
659 : bool for_tie_p)
660 : {
661 14720840 : int use, use_match;
662 14720840 : ira_allocno_t a;
663 14720840 : enum reg_class use_cl, acl;
664 14720840 : bool advance_p;
665 14720840 : rtx dreg = recog_data.operand[def];
666 14720840 : rtx orig_dreg = dreg;
667 :
668 14720840 : if (def_cl == NO_REGS)
669 : return;
670 :
671 14720840 : if (GET_CODE (dreg) == SUBREG)
672 111896 : dreg = SUBREG_REG (dreg);
673 :
674 14720840 : if (! REG_P (dreg) || REGNO (dreg) < FIRST_PSEUDO_REGISTER)
675 : return;
676 :
677 12497435 : a = ira_curr_regno_allocno_map[REGNO (dreg)];
678 12497435 : acl = ALLOCNO_CLASS (a);
679 12497435 : if (! reg_classes_intersect_p (acl, def_cl))
680 : return;
681 :
682 12304506 : advance_p = true;
683 :
684 12304506 : int n_operands = recog_data.n_operands;
685 12304506 : const operand_alternative *op_alt = &recog_op_alt[alt * n_operands];
686 50979048 : for (use = 0; use < n_operands; use++)
687 : {
688 38674542 : int alt1;
689 :
690 38674542 : if (use == def || recog_data.operand_type[use] == OP_OUT)
691 12467542 : 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 38430050 : if (op_alt[use].matches == def
701 26207000 : || (for_tie_p
702 13719724 : && rtx_equal_p (recog_data.operand[use],
703 13719724 : recog_data.operand[op_alt[def].matched])))
704 12223050 : continue;
705 :
706 13983950 : if (op_alt[use].anything_ok)
707 : use_cl = ALL_REGS;
708 : else
709 12224474 : use_cl = op_alt[use].cl;
710 12224474 : if (use_cl == NO_REGS)
711 4821579 : 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 9162371 : if (for_tie_p && targetm.class_likely_spilled_p (use_cl))
718 1026307 : 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 21544340 : for (alt1 = 0; alt1 < recog_data.n_alternatives; alt1++)
728 : {
729 18528286 : if (!TEST_BIT (preferred_alternatives, alt1))
730 8820523 : continue;
731 9707763 : const operand_alternative *op_alt1
732 9707763 : = &recog_op_alt[alt1 * n_operands];
733 9707763 : if (op_alt1[use].matches == def
734 7712915 : || (use < n_operands - 1
735 2967206 : && recog_data.constraints[use][0] == '%'
736 8141 : && op_alt1[use + 1].matches == def)
737 7712915 : || (use >= 1
738 7711398 : && recog_data.constraints[use - 1][0] == '%'
739 3128356 : && op_alt1[use - 1].matches == def))
740 : break;
741 4595285 : if (for_tie_p
742 4375112 : && !op_alt1[def].earlyclobber
743 4373948 : && op_alt1[def].matched < 0
744 29829 : && alternative_class (op_alt1, def) != NO_REGS
745 4625114 : && alternative_class (op_alt1, use) != NO_REGS)
746 : break;
747 : }
748 :
749 8136064 : if (alt1 < recog_data.n_alternatives)
750 5120010 : continue;
751 :
752 3016054 : advance_p = check_and_make_def_use_conflict (dreg, orig_dreg, def_cl,
753 : use, use_cl, advance_p);
754 :
755 3016054 : 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 85629969 : make_early_clobber_and_input_conflicts (void)
779 : {
780 85629969 : int alt;
781 85629969 : int def, def_match;
782 85629969 : enum reg_class def_cl;
783 :
784 85629969 : int n_alternatives = recog_data.n_alternatives;
785 85629969 : int n_operands = recog_data.n_operands;
786 85629969 : const operand_alternative *op_alt = recog_op_alt;
787 1185792560 : for (alt = 0; alt < n_alternatives; alt++, op_alt += n_operands)
788 1100162591 : if (TEST_BIT (preferred_alternatives, alt))
789 395037864 : for (def = 0; def < n_operands; def++)
790 : {
791 272727942 : if (op_alt[def].anything_ok)
792 : def_cl = ALL_REGS;
793 : else
794 258257733 : def_cl = op_alt[def].cl;
795 258257733 : if (def_cl != NO_REGS)
796 : {
797 215976630 : if (op_alt[def].earlyclobber)
798 146558 : check_and_make_def_conflict (alt, def, def_cl, false);
799 215830072 : else if (op_alt[def].matched >= 0
800 215830072 : && !targetm.class_likely_spilled_p (def_cl))
801 14534776 : check_and_make_def_conflict (alt, def, def_cl, true);
802 : }
803 :
804 272727942 : if ((def_match = op_alt[def].matches) >= 0
805 272727942 : && (op_alt[def_match].earlyclobber
806 15241556 : || op_alt[def].earlyclobber))
807 : {
808 39506 : if (op_alt[def_match].anything_ok)
809 : def_cl = ALL_REGS;
810 : else
811 39506 : def_cl = op_alt[def_match].cl;
812 39506 : check_and_make_def_conflict (alt, def, def_cl, false);
813 : }
814 : }
815 85629969 : }
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 96443140 : mark_hard_reg_early_clobbers (rtx_insn *insn, bool live_p)
821 : {
822 96443140 : df_ref def;
823 96443140 : bool set_p = false;
824 :
825 705502160 : FOR_EACH_INSN_DEF (def, insn)
826 609059020 : if (DF_REF_FLAGS_IS_SET (def, DF_REF_MUST_CLOBBER))
827 : {
828 22048370 : rtx dreg = DF_REF_REG (def);
829 :
830 22048370 : if (GET_CODE (dreg) == SUBREG)
831 0 : dreg = SUBREG_REG (dreg);
832 22048370 : if (! REG_P (dreg) || REGNO (dreg) >= FIRST_PSEUDO_REGISTER)
833 128914 : 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 21919456 : if (live_p)
839 10959728 : mark_ref_live (def);
840 : else
841 10959728 : mark_ref_dead (def);
842 : set_p = true;
843 : }
844 :
845 96443140 : 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 register. Otherwise it returns -1. */
850 : static int
851 181399312 : single_reg_class_regno (const char *constraints, rtx op, rtx equiv_const)
852 : {
853 181399312 : int c;
854 181399312 : int regno, next_regno;
855 181399312 : enum reg_class next_cl;
856 181399312 : enum constraint_num cn;
857 :
858 181399312 : regno = -1;
859 181399312 : alternative_mask preferred = preferred_alternatives;
860 948780456 : while ((c = *constraints))
861 : {
862 934410641 : if (c == '#')
863 0 : preferred &= ~ALTERNATIVE_BIT (0);
864 934410641 : else if (c == ',')
865 255846657 : preferred >>= 1;
866 678563984 : else if (preferred & 1)
867 204275208 : switch (c)
868 : {
869 : case 'g':
870 : return -1;
871 :
872 135 : case '{':
873 135 : next_regno = decode_hard_reg_constraint (constraints);
874 135 : if (regno >= 0 && regno != next_regno)
875 : return -1;
876 : regno = next_regno;
877 : break;
878 :
879 183916011 : default:
880 : /* ??? Is this the best way to handle memory constraints? */
881 183916011 : cn = lookup_constraint (constraints);
882 183916011 : if (insn_extra_memory_constraint (cn)
883 171580155 : || insn_extra_special_memory_constraint (cn)
884 : || insn_extra_relaxed_memory_constraint (cn)
885 355496164 : || insn_extra_address_constraint (cn))
886 : return -1;
887 170991371 : if (constraint_satisfied_p (op, cn)
888 170991371 : || (equiv_const != NULL_RTX
889 0 : && CONSTANT_P (equiv_const)
890 0 : && constraint_satisfied_p (equiv_const, cn)))
891 : return -1;
892 156124784 : next_cl = reg_class_for_constraint (cn);
893 124195967 : if (next_cl == NO_REGS)
894 : break;
895 120932828 : next_regno = ira_class_singleton[next_cl][GET_MODE (op)];
896 120932828 : if (regno < 0
897 120932828 : ? next_regno < 0
898 : : regno != next_regno)
899 : return -1;
900 : regno = next_regno;
901 : break;
902 :
903 13119974 : case '0': case '1': case '2': case '3': case '4':
904 13119974 : case '5': case '6': case '7': case '8': case '9':
905 13119974 : {
906 13119974 : char *end;
907 13119974 : unsigned long dup = strtoul (constraints, &end, 10);
908 13119974 : constraints = end;
909 13119974 : next_regno
910 26239948 : = single_reg_class_regno (recog_data.constraints[dup],
911 13119974 : recog_data.operand[dup], NULL_RTX);
912 13119974 : if (regno < 0
913 13119974 : ? next_regno < 0
914 : : regno != next_regno)
915 12883609 : return -1;
916 236365 : regno = next_regno;
917 236365 : continue;
918 236365 : }
919 : }
920 767144779 : constraints += CONSTRAINT_LEN (c, constraints);
921 : }
922 : return regno;
923 : }
924 :
925 : /* The function checks that operand OP_NUM of the current insn can use
926 : only one hard register. If it is so, the function returns the
927 : hard register. Otherwise it returns -1. */
928 : static int
929 183620622 : single_reg_operand_class_regno (int op_num)
930 : {
931 183620622 : if (op_num < 0 || recog_data.n_alternatives == 0)
932 : return -1;
933 168279338 : return single_reg_class_regno (recog_data.constraints[op_num],
934 168279338 : recog_data.operand[op_num], NULL_RTX);
935 : }
936 :
937 : /* The function sets up hard register set *SET to hard registers which
938 : might be used by insn reloads because the constraints are too
939 : strict. */
940 : void
941 28543 : ira_implicitly_set_insn_hard_regs (HARD_REG_SET *set,
942 : alternative_mask preferred)
943 : {
944 28543 : int i, c, regno = 0;
945 28543 : enum reg_class cl;
946 28543 : rtx op;
947 28543 : machine_mode mode;
948 :
949 28543 : CLEAR_HARD_REG_SET (*set);
950 87932 : for (i = 0; i < recog_data.n_operands; i++)
951 : {
952 59389 : op = recog_data.operand[i];
953 :
954 59389 : if (GET_CODE (op) == SUBREG)
955 1075 : op = SUBREG_REG (op);
956 :
957 59389 : if (GET_CODE (op) == SCRATCH
958 59389 : || (REG_P (op) && (regno = REGNO (op)) >= FIRST_PSEUDO_REGISTER))
959 : {
960 39149 : const char *p = recog_data.constraints[i];
961 :
962 78298 : mode = (GET_CODE (op) == SCRATCH
963 39149 : ? GET_MODE (op) : PSEUDO_REGNO_MODE (regno));
964 39149 : cl = NO_REGS;
965 39149 : for (alternative_mask curr_preferred = preferred;
966 1487036 : (c = *p);
967 1447887 : p += CONSTRAINT_LEN (c, p))
968 1447887 : if (c == '#')
969 0 : curr_preferred &= ~ALTERNATIVE_BIT (0);
970 1447887 : else if (c == ',')
971 496188 : curr_preferred >>= 1;
972 951699 : else if (curr_preferred & 1)
973 : {
974 598279 : cl = reg_class_for_constraint (lookup_constraint (p));
975 262159 : if (cl != NO_REGS)
976 : {
977 : /* There is no register pressure problem if all of the
978 : regs in this class are fixed. */
979 257359 : int regno = ira_class_singleton[cl][mode];
980 257359 : if (regno >= 0)
981 1612 : add_to_hard_reg_set (set, mode, regno);
982 : }
983 340920 : else if (c == '{')
984 : {
985 0 : int regno = decode_hard_reg_constraint (p);
986 0 : gcc_assert (regno >= 0 && regno < FIRST_PSEUDO_REGISTER);
987 0 : add_to_hard_reg_set (set, mode, regno);
988 : }
989 : }
990 : }
991 : }
992 28543 : }
993 : /* Processes input operands, if IN_P, or output operands otherwise of
994 : the current insn with FREQ to find allocno which can use only one
995 : hard register and makes other currently living allocnos conflicting
996 : with the hard register. */
997 : static void
998 171259938 : process_single_reg_constrained_operands (bool in_p, int freq)
999 : {
1000 171259938 : int i, regno, hard_regno;
1001 171259938 : unsigned int px;
1002 171259938 : enum reg_class cl;
1003 171259938 : rtx operand;
1004 171259938 : ira_allocno_t operand_a, a;
1005 :
1006 538338916 : for (i = 0; i < recog_data.n_operands; i++)
1007 : {
1008 367078978 : operand = recog_data.operand[i];
1009 367078978 : if (in_p && recog_data.operand_type[i] != OP_IN
1010 62629796 : && recog_data.operand_type[i] != OP_INOUT)
1011 366287464 : continue;
1012 183539489 : if (! in_p && recog_data.operand_type[i] != OP_OUT
1013 120990826 : && recog_data.operand_type[i] != OP_INOUT)
1014 120909693 : continue;
1015 183620622 : hard_regno = single_reg_operand_class_regno (i);
1016 183620622 : if (hard_regno < 0)
1017 182829108 : continue;
1018 :
1019 791514 : operand_a = NULL;
1020 :
1021 791514 : if (GET_CODE (operand) == SUBREG)
1022 60645 : operand = SUBREG_REG (operand);
1023 :
1024 791514 : if (REG_P (operand)
1025 791514 : && (regno = REGNO (operand)) >= FIRST_PSEUDO_REGISTER)
1026 : {
1027 774632 : enum reg_class aclass;
1028 :
1029 774632 : cl = NO_REGS;
1030 774632 : int nregs = hard_regno_nregs (hard_regno, recog_data.operand_mode[i]);
1031 1584316 : for (int j = 0; j < nregs; ++j)
1032 809684 : cl = reg_class_superunion[cl][REGNO_REG_CLASS (hard_regno + j)];
1033 :
1034 774632 : operand_a = ira_curr_regno_allocno_map[regno];
1035 774632 : aclass = ALLOCNO_CLASS (operand_a);
1036 774632 : if (ira_class_subset_p[cl][aclass])
1037 : {
1038 : /* View the desired allocation of OPERAND as:
1039 :
1040 : (REG:YMODE YREGNO),
1041 :
1042 : a simplification of:
1043 :
1044 : (subreg:YMODE (reg:XMODE XREGNO) OFFSET). */
1045 766277 : machine_mode ymode, xmode;
1046 766277 : int xregno, yregno;
1047 766277 : poly_int64 offset;
1048 :
1049 766277 : xmode = recog_data.operand_mode[i];
1050 766277 : xregno = hard_regno;
1051 766277 : gcc_assert (xregno >= 0);
1052 766277 : ymode = ALLOCNO_MODE (operand_a);
1053 766277 : offset = subreg_lowpart_offset (ymode, xmode);
1054 766277 : yregno = simplify_subreg_regno (xregno, xmode, offset, ymode);
1055 766277 : if (yregno >= 0
1056 766277 : && ira_class_hard_reg_index[aclass][yregno] >= 0)
1057 : {
1058 766277 : int cost;
1059 :
1060 766277 : ira_allocate_and_set_costs
1061 766277 : (&ALLOCNO_CONFLICT_HARD_REG_COSTS (operand_a),
1062 : aclass, 0);
1063 766277 : ira_init_register_move_cost_if_necessary (xmode);
1064 1532554 : cost = freq * (in_p
1065 766277 : ? ira_register_move_cost[xmode][aclass][cl]
1066 439281 : : ira_register_move_cost[xmode][cl][aclass]);
1067 766277 : ALLOCNO_CONFLICT_HARD_REG_COSTS (operand_a)
1068 766277 : [ira_class_hard_reg_index[aclass][yregno]] -= cost;
1069 : }
1070 : }
1071 : }
1072 :
1073 791514 : HARD_REG_SET hard_regs;
1074 791514 : CLEAR_HARD_REG_SET (hard_regs);
1075 791514 : add_to_hard_reg_set (&hard_regs, recog_data.operand_mode[i], hard_regno);
1076 :
1077 31452156 : EXECUTE_IF_SET_IN_SPARSESET (objects_live, px)
1078 : {
1079 30660642 : ira_object_t obj = ira_object_id_map[px];
1080 30660642 : a = OBJECT_ALLOCNO (obj);
1081 30660642 : if (a != operand_a)
1082 : {
1083 : /* We could increase costs of A instead of making it
1084 : conflicting with the hard register. But it works worse
1085 : because it will be spilled in reload in anyway. */
1086 89537826 : OBJECT_CONFLICT_HARD_REGS (obj) |= hard_regs;
1087 30660642 : OBJECT_TOTAL_CONFLICT_HARD_REGS (obj) |= hard_regs;
1088 : }
1089 : }
1090 : }
1091 171259938 : }
1092 :
1093 : /* Go through the operands of the extracted insn looking for operand
1094 : alternatives that apply a register filter. Record any such filters
1095 : in the operand's allocno. */
1096 : static void
1097 85629969 : process_register_constraint_filters ()
1098 : {
1099 269169458 : for (int opno = 0; opno < recog_data.n_operands; ++opno)
1100 : {
1101 183539489 : rtx op = recog_data.operand[opno];
1102 183539489 : if (SUBREG_P (op))
1103 3047118 : op = SUBREG_REG (op);
1104 183539489 : if (REG_P (op) && !HARD_REGISTER_P (op))
1105 : {
1106 75922799 : ira_allocno_t a = ira_curr_regno_allocno_map[REGNO (op)];
1107 1086770093 : for (int alt = 0; alt < recog_data.n_alternatives; alt++)
1108 : {
1109 1010847294 : if (!TEST_BIT (preferred_alternatives, alt))
1110 885120943 : continue;
1111 :
1112 125726351 : auto *op_alt = &recog_op_alt[alt * recog_data.n_operands];
1113 125726351 : auto cl = alternative_class (op_alt, opno);
1114 : /* The two extremes are easy:
1115 :
1116 : - We should record the filter if CL matches the
1117 : allocno class.
1118 :
1119 : - We should ignore the filter if CL and the allocno class
1120 : are disjoint. We'll either pick a different alternative
1121 : or reload the operand.
1122 :
1123 : Things are trickier if the classes overlap. However:
1124 :
1125 : - If the allocno class includes registers that are not
1126 : in CL, some choices of hard register will need a reload
1127 : anyway. It isn't obvious that reloads due to filters
1128 : are worse than reloads due to regnos being outside CL.
1129 :
1130 : - Conversely, if the allocno class is a subset of CL,
1131 : any allocation will satisfy the class requirement.
1132 : We should try to make sure it satisfies the filter
1133 : requirement too. This is useful if, for example,
1134 : an allocno needs to be in "low" registers to satisfy
1135 : some uses, and its allocno class is therefore those
1136 : low registers, but the allocno is elsewhere allowed
1137 : to be in any even-numbered register. Picking an
1138 : even-numbered low register satisfies both types of use. */
1139 125726351 : if (!ira_class_subset_p[ALLOCNO_CLASS (a)][cl])
1140 29420795 : continue;
1141 :
1142 96305556 : auto filters = alternative_register_filters (op_alt, opno);
1143 96305556 : if (!filters)
1144 96305556 : continue;
1145 :
1146 0 : filters |= ALLOCNO_REGISTER_FILTERS (a);
1147 0 : ALLOCNO_SET_REGISTER_FILTERS (a, filters);
1148 : }
1149 : }
1150 : }
1151 85629969 : }
1152 :
1153 : /* Append a dependent filter ID with mode MODE, referenced allocno
1154 : REF_ALLOCNO, hardreg REF_HARD_REGNO, and REF_MODE to allocno A. */
1155 :
1156 : void
1157 0 : ira_add_dependent_filter (ira_allocno_t a, int id,
1158 : machine_mode mode, ira_allocno_t ref_allocno,
1159 : unsigned int ref_hard_regno, machine_mode ref_mode)
1160 : {
1161 : /* Check if we already have the filter that should be added.
1162 : This is a linear search and the assumption is that we'll never
1163 : have more than a handful of dependent filters. Right now, the
1164 : maximum is 32 (see gensupport.cc). */
1165 0 : for (auto *filter = ALLOCNO_DEPENDENT_FILTERS (a);
1166 0 : filter;
1167 0 : filter = filter->next)
1168 0 : if (filter->id == id
1169 0 : && filter->ref_allocno == ref_allocno
1170 0 : && filter->ref_hard_regno == ref_hard_regno
1171 0 : && filter->mode == mode
1172 0 : && filter->ref_mode == ref_mode)
1173 : return;
1174 :
1175 0 : auto *filter = (ira_dependent_filter *)
1176 0 : ira_allocate (sizeof (ira_dependent_filter));
1177 0 : filter->id = id;
1178 0 : filter->ref_allocno = ref_allocno;
1179 0 : filter->ref_hard_regno = ref_hard_regno;
1180 0 : filter->mode = mode;
1181 0 : filter->ref_mode = ref_mode;
1182 0 : filter->next = ALLOCNO_DEPENDENT_FILTERS (a);
1183 0 : ALLOCNO_DEPENDENT_FILTERS (a) = filter;
1184 : }
1185 :
1186 : /* Walk the operand alternatives of the current insn. For each
1187 : operand with a dependent-filter constraint, add one
1188 : ira_dependent_filter in the appropriate allocno. */
1189 :
1190 : static void
1191 0 : process_dependent_filters ()
1192 : {
1193 0 : if (!NUM_DEPENDENT_FILTERS)
1194 0 : return;
1195 :
1196 : for (int opno = 0; opno < recog_data.n_operands; ++opno)
1197 : {
1198 : rtx op = recog_data.operand[opno];
1199 : if (!REG_P (op) || HARD_REGISTER_P (op))
1200 : continue;
1201 :
1202 : ira_allocno_t a = ira_curr_regno_allocno_map[REGNO (op)];
1203 :
1204 : for (int alt = 0; alt < recog_data.n_alternatives; alt++)
1205 : {
1206 : if (!TEST_BIT (preferred_alternatives, alt))
1207 : continue;
1208 :
1209 : auto *op_alt = &recog_op_alt[alt * recog_data.n_operands];
1210 : auto cl = alternative_class (op_alt, opno);
1211 : if (!ira_class_subset_p[ALLOCNO_CLASS (a)][cl])
1212 : continue;
1213 :
1214 : auto dep_filter_mask = alternative_dependent_filters (op_alt, opno);
1215 : if (!dep_filter_mask)
1216 : continue;
1217 :
1218 : for (int id = 0; id < NUM_DEPENDENT_FILTERS; ++id)
1219 : {
1220 : if (!(dep_filter_mask & (1U << id)))
1221 : continue;
1222 :
1223 : int ref_opno = get_dependent_filter_ref (id);
1224 : if (ref_opno < 0 || ref_opno >= recog_data.n_operands)
1225 : continue;
1226 : rtx ref_op = recog_data.operand[ref_opno];
1227 : if (!REG_P (ref_op))
1228 : continue;
1229 :
1230 : ira_allocno_t ref_a = NULL;
1231 : unsigned int ref_hard_regno = INVALID_REGNUM;
1232 : if (HARD_REGISTER_P (ref_op))
1233 : ref_hard_regno = REGNO (ref_op);
1234 : else
1235 : ref_a = ira_curr_regno_allocno_map[REGNO (ref_op)];
1236 :
1237 : ira_add_dependent_filter (a, id, GET_MODE (op),
1238 : ref_a, ref_hard_regno,
1239 : GET_MODE (ref_op));
1240 : }
1241 : }
1242 : }
1243 : }
1244 :
1245 : /* Look through the CALL_INSN_FUNCTION_USAGE of a call insn INSN, and see if
1246 : we find a SET rtx that we can use to deduce that a register can be cheaply
1247 : caller-saved. Return such a register, or NULL_RTX if none is found. */
1248 : static rtx
1249 6173298 : find_call_crossed_cheap_reg (rtx_call_insn *insn)
1250 : {
1251 6173298 : rtx cheap_reg = NULL_RTX;
1252 6173298 : rtx exp = CALL_INSN_FUNCTION_USAGE (insn);
1253 :
1254 18114610 : while (exp != NULL)
1255 : {
1256 12095324 : rtx x = XEXP (exp, 0);
1257 12095324 : if (GET_CODE (x) == SET)
1258 : {
1259 : exp = x;
1260 : break;
1261 : }
1262 11941312 : exp = XEXP (exp, 1);
1263 : }
1264 6173298 : if (exp != NULL)
1265 : {
1266 154012 : basic_block bb = BLOCK_FOR_INSN (insn);
1267 154012 : rtx reg = SET_SRC (exp);
1268 154012 : rtx_insn *prev = PREV_INSN (insn);
1269 308043 : while (prev && !(INSN_P (prev)
1270 154012 : && BLOCK_FOR_INSN (prev) != bb))
1271 : {
1272 154031 : if (NONDEBUG_INSN_P (prev))
1273 : {
1274 154012 : rtx set = single_set (prev);
1275 :
1276 154012 : if (set && rtx_equal_p (SET_DEST (set), reg))
1277 : {
1278 154012 : rtx src = SET_SRC (set);
1279 122257 : if (!REG_P (src) || HARD_REGISTER_P (src)
1280 275849 : || !pseudo_regno_single_word_and_live_p (REGNO (src)))
1281 : break;
1282 33874 : if (!modified_between_p (src, prev, insn))
1283 6173298 : cheap_reg = src;
1284 : break;
1285 : }
1286 0 : if (set && rtx_equal_p (SET_SRC (set), reg))
1287 : {
1288 0 : rtx dest = SET_DEST (set);
1289 0 : if (!REG_P (dest) || HARD_REGISTER_P (dest)
1290 0 : || !pseudo_regno_single_word_and_live_p (REGNO (dest)))
1291 : break;
1292 0 : if (!modified_between_p (dest, prev, insn))
1293 6173298 : cheap_reg = dest;
1294 : break;
1295 : }
1296 :
1297 0 : if (reg_set_p (reg, prev))
1298 : break;
1299 : }
1300 19 : prev = PREV_INSN (prev);
1301 : }
1302 : }
1303 6173298 : return cheap_reg;
1304 : }
1305 :
1306 : /* Determine whether INSN is a register to register copy of the type where
1307 : we do not need to make the source and destiniation registers conflict.
1308 : If this is a copy instruction, then return the source reg. Otherwise,
1309 : return NULL_RTX. */
1310 : rtx
1311 313847266 : non_conflicting_reg_copy_p (rtx_insn *insn)
1312 : {
1313 : /* Reload has issues with overlapping pseudos being assigned to the
1314 : same hard register, so don't allow it. See PR87600 for details. */
1315 313847266 : if (!targetm.lra_p ())
1316 : return NULL_RTX;
1317 :
1318 313847266 : rtx set = single_set (insn);
1319 :
1320 : /* Disallow anything other than a simple register to register copy
1321 : that has no side effects. */
1322 313847266 : if (set == NULL_RTX
1323 298429987 : || !REG_P (SET_DEST (set))
1324 219936957 : || !REG_P (SET_SRC (set))
1325 388168059 : || side_effects_p (set))
1326 : return NULL_RTX;
1327 :
1328 74320793 : int dst_regno = REGNO (SET_DEST (set));
1329 74320793 : int src_regno = REGNO (SET_SRC (set));
1330 74320793 : machine_mode mode = GET_MODE (SET_DEST (set));
1331 :
1332 : /* By definition, a register does not conflict with itself, therefore we
1333 : do not have to handle it specially. Returning NULL_RTX now, helps
1334 : simplify the callers of this function. */
1335 74320793 : if (dst_regno == src_regno)
1336 : return NULL_RTX;
1337 :
1338 : /* Computing conflicts for register pairs is difficult to get right, so
1339 : for now, disallow it. */
1340 74320793 : if ((HARD_REGISTER_NUM_P (dst_regno)
1341 20391107 : && hard_regno_nregs (dst_regno, mode) != 1)
1342 94546123 : || (HARD_REGISTER_NUM_P (src_regno)
1343 10703768 : && hard_regno_nregs (src_regno, mode) != 1))
1344 312252 : return NULL_RTX;
1345 :
1346 : return SET_SRC (set);
1347 : }
1348 :
1349 : #ifdef EH_RETURN_DATA_REGNO
1350 :
1351 : /* Add EH return hard registers as conflict hard registers to allocnos
1352 : living at end of BB. For most allocnos it is already done in
1353 : process_bb_node_lives when we processing input edges but it does
1354 : not work when and EH edge is edge out of the current region. This
1355 : function covers such out of region edges. */
1356 : static void
1357 14722482 : process_out_of_region_eh_regs (basic_block bb)
1358 : {
1359 14722482 : edge e;
1360 14722482 : edge_iterator ei;
1361 14722482 : unsigned int i;
1362 14722482 : bitmap_iterator bi;
1363 14722482 : bool eh_p = false;
1364 :
1365 35751511 : FOR_EACH_EDGE (e, ei, bb->succs)
1366 21029029 : if ((e->flags & EDGE_EH)
1367 21029029 : && IRA_BB_NODE (e->dest)->parent != IRA_BB_NODE (bb)->parent)
1368 21029029 : eh_p = true;
1369 :
1370 14722482 : if (! eh_p)
1371 14714266 : return;
1372 :
1373 111858 : EXECUTE_IF_SET_IN_BITMAP (df_get_live_out (bb), FIRST_PSEUDO_REGISTER, i, bi)
1374 : {
1375 103642 : ira_allocno_t a = ira_curr_regno_allocno_map[i];
1376 213378 : for (int n = ALLOCNO_NUM_OBJECTS (a) - 1; n >= 0; n--)
1377 : {
1378 109736 : ira_object_t obj = ALLOCNO_OBJECT (a, n);
1379 438944 : OBJECT_CONFLICT_HARD_REGS (obj) |= eh_return_data_regs;
1380 109736 : OBJECT_TOTAL_CONFLICT_HARD_REGS (obj) |= eh_return_data_regs;
1381 : }
1382 : }
1383 : }
1384 :
1385 : #endif
1386 :
1387 : /* Add conflicts for object OBJ from REGION landing pads using CALLEE_ABI. */
1388 : static void
1389 3709728 : add_conflict_from_region_landing_pads (eh_region region, ira_object_t obj,
1390 : function_abi callee_abi)
1391 : {
1392 3709728 : ira_allocno_t a = OBJECT_ALLOCNO (obj);
1393 3709728 : rtx_code_label *landing_label;
1394 3709728 : basic_block landing_bb;
1395 :
1396 7095691 : for (eh_landing_pad lp = region->landing_pads; lp ; lp = lp->next_lp)
1397 : {
1398 5841806 : if ((landing_label = lp->landing_pad) != NULL
1399 5841806 : && (landing_bb = BLOCK_FOR_INSN (landing_label)) != NULL
1400 11683557 : && (region->type != ERT_CLEANUP
1401 4304069 : || bitmap_bit_p (df_get_live_in (landing_bb),
1402 : ALLOCNO_REGNO (a))))
1403 : {
1404 2455843 : HARD_REG_SET new_conflict_regs
1405 2455843 : = callee_abi.mode_clobbers (ALLOCNO_MODE (a));
1406 9823372 : OBJECT_CONFLICT_HARD_REGS (obj) |= new_conflict_regs;
1407 2455843 : OBJECT_TOTAL_CONFLICT_HARD_REGS (obj) |= new_conflict_regs;
1408 2455843 : return;
1409 : }
1410 : }
1411 : }
1412 :
1413 : /* Process insns of the basic block given by its LOOP_TREE_NODE to
1414 : update allocno live ranges, allocno hard register conflicts,
1415 : intersected calls, and register pressure info for allocnos for the
1416 : basic block for and regions containing the basic block. */
1417 : static void
1418 16864148 : process_bb_node_lives (ira_loop_tree_node_t loop_tree_node)
1419 : {
1420 16864148 : int i, freq;
1421 16864148 : unsigned int j, k;
1422 16864148 : basic_block bb;
1423 16864148 : rtx_insn *insn;
1424 16864148 : bitmap_iterator bi;
1425 16864148 : bitmap reg_live_out;
1426 16864148 : unsigned int px;
1427 16864148 : bool set_p;
1428 :
1429 16864148 : bb = loop_tree_node->bb;
1430 16864148 : if (bb != NULL)
1431 : {
1432 72449714 : for (i = 0; i < ira_pressure_classes_num; i++)
1433 : {
1434 57727232 : curr_reg_pressure[ira_pressure_classes[i]] = 0;
1435 57727232 : high_pressure_start_point[ira_pressure_classes[i]] = -1;
1436 : }
1437 14722482 : curr_bb_node = loop_tree_node;
1438 14722482 : reg_live_out = df_get_live_out (bb);
1439 14722482 : sparseset_clear (objects_live);
1440 29444964 : REG_SET_TO_HARD_REG_SET (hard_regs_live, reg_live_out);
1441 14722482 : hard_regs_live &= ~(eliminable_regset | ira_no_alloc_regs);
1442 14722482 : hard_reg_set_iterator hrsi;
1443 14722482 : k = 0;
1444 15870233 : EXECUTE_IF_SET_IN_HARD_REG_SET (hard_regs_live, 0, k, hrsi)
1445 : {
1446 1147751 : enum reg_class aclass, pclass, cl;
1447 :
1448 1147751 : aclass = ira_allocno_class_translate[REGNO_REG_CLASS (k)];
1449 1147751 : pclass = ira_pressure_class_translate[aclass];
1450 10888548 : for (j = 0;
1451 10888548 : (cl = ira_reg_class_super_classes[pclass][j])
1452 10888548 : != LIM_REG_CLASSES;
1453 : j++)
1454 : {
1455 9740797 : if (! ira_reg_pressure_class_p[cl])
1456 8593046 : continue;
1457 1147751 : curr_reg_pressure[cl]++;
1458 1147751 : if (curr_bb_node->reg_pressure[cl] < curr_reg_pressure[cl])
1459 1147751 : curr_bb_node->reg_pressure[cl] = curr_reg_pressure[cl];
1460 1147751 : ira_assert (curr_reg_pressure[cl]
1461 : <= ira_class_hard_regs_num[cl]);
1462 : }
1463 : }
1464 155969627 : EXECUTE_IF_SET_IN_BITMAP (reg_live_out, FIRST_PSEUDO_REGISTER, j, bi)
1465 141247145 : mark_pseudo_regno_live (j);
1466 :
1467 : #ifdef EH_RETURN_DATA_REGNO
1468 14722482 : process_out_of_region_eh_regs (bb);
1469 : #endif
1470 :
1471 14722482 : freq = REG_FREQ_FROM_BB (bb);
1472 8740580 : if (freq == 0)
1473 2089713 : freq = 1;
1474 :
1475 : /* Invalidate all allocno_saved_at_call entries. */
1476 14722482 : last_call_num++;
1477 :
1478 : /* Scan the code of this basic block, noting which allocnos and
1479 : hard regs are born or die.
1480 :
1481 : Note that this loop treats uninitialized values as live until
1482 : the beginning of the block. For example, if an instruction
1483 : uses (reg:DI foo), and only (subreg:SI (reg:DI foo) 0) is ever
1484 : set, FOO will remain live until the beginning of the block.
1485 : Likewise if FOO is not set at all. This is unnecessarily
1486 : pessimistic, but it probably doesn't matter much in practice. */
1487 180089899 : FOR_BB_INSNS_REVERSE (bb, insn)
1488 : {
1489 165367417 : ira_allocno_t a;
1490 165367417 : df_ref def, use;
1491 165367417 : bool call_p;
1492 :
1493 165367417 : if (!NONDEBUG_INSN_P (insn))
1494 79737448 : continue;
1495 :
1496 85629969 : if (internal_flag_ira_verbose > 2 && ira_dump_file != NULL)
1497 1477 : fprintf (ira_dump_file, " Insn %u(l%d): point = %d\n",
1498 1477 : INSN_UID (insn), loop_tree_node->parent->loop_num,
1499 : curr_point);
1500 :
1501 85629969 : call_p = CALL_P (insn);
1502 85629969 : ignore_reg_for_conflicts = non_conflicting_reg_copy_p (insn);
1503 :
1504 : /* Mark each defined value as live. We need to do this for
1505 : unused values because they still conflict with quantities
1506 : that are live at the time of the definition.
1507 :
1508 : Ignore DF_REF_MAY_CLOBBERs on a call instruction. Such
1509 : references represent the effect of the called function
1510 : on a call-clobbered register. Marking the register as
1511 : live would stop us from allocating it to a call-crossing
1512 : allocno. */
1513 672971203 : FOR_EACH_INSN_DEF (def, insn)
1514 587341234 : if (!call_p || !DF_REF_FLAGS_IS_SET (def, DF_REF_MAY_CLOBBER))
1515 71801678 : mark_ref_live (def);
1516 :
1517 : /* If INSN has multiple outputs, then any value used in one
1518 : of the outputs conflicts with the other outputs. Model this
1519 : by making the used value live during the output phase.
1520 :
1521 : It is unsafe to use !single_set here since it will ignore
1522 : an unused output. Just because an output is unused does
1523 : not mean the compiler can assume the side effect will not
1524 : occur. Consider if ALLOCNO appears in the address of an
1525 : output and we reload the output. If we allocate ALLOCNO
1526 : to the same hard register as an unused output we could
1527 : set the hard register before the output reload insn. */
1528 85629969 : if (GET_CODE (PATTERN (insn)) == PARALLEL && multiple_sets (insn))
1529 1886791 : FOR_EACH_INSN_USE (use, insn)
1530 : {
1531 1485173 : int i;
1532 1485173 : rtx reg;
1533 :
1534 1485173 : reg = DF_REF_REG (use);
1535 4729886 : for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1536 : {
1537 3646501 : rtx set;
1538 :
1539 3646501 : set = XVECEXP (PATTERN (insn), 0, i);
1540 3646501 : if (GET_CODE (set) == SET
1541 3646501 : && reg_overlap_mentioned_p (reg, SET_DEST (set)))
1542 : {
1543 : /* After the previous loop, this is a no-op if
1544 : REG is contained within SET_DEST (SET). */
1545 401788 : mark_ref_live (use);
1546 401788 : break;
1547 : }
1548 : }
1549 : }
1550 :
1551 85629969 : preferred_alternatives = ira_setup_alts (insn);
1552 85629969 : process_register_constraint_filters ();
1553 85629969 : process_dependent_filters ();
1554 85629969 : process_single_reg_constrained_operands (false, freq);
1555 :
1556 85629969 : if (auto call = dyn_cast<rtx_call_insn *> (insn))
1557 : {
1558 : /* Try to find a SET in the CALL_INSN_FUNCTION_USAGE, and from
1559 : there, try to find a pseudo that is live across the call but
1560 : can be cheaply reconstructed from the return value. */
1561 6173298 : rtx cheap_reg = find_call_crossed_cheap_reg (call);
1562 6173298 : if (cheap_reg != NULL_RTX)
1563 33874 : add_reg_note (call, REG_RETURNED, cheap_reg);
1564 :
1565 6173298 : last_call_num++;
1566 6173298 : sparseset_clear (allocnos_processed);
1567 : /* The current set of live allocnos are live across the call. */
1568 470898852 : EXECUTE_IF_SET_IN_SPARSESET (objects_live, i)
1569 : {
1570 229276128 : ira_object_t obj = ira_object_id_map[i];
1571 229276128 : a = OBJECT_ALLOCNO (obj);
1572 229276128 : int num = ALLOCNO_NUM (a);
1573 229276128 : function_abi callee_abi = insn_callee_abi (call);
1574 :
1575 : /* Don't allocate allocnos that cross setjmps or any
1576 : call, if this function receives a nonlocal
1577 : goto. */
1578 229276128 : if (cfun->has_nonlocal_label
1579 229276128 : || (!targetm.setjmp_preserves_nonvolatile_regs_p ()
1580 229273506 : && (find_reg_note (call, REG_SETJMP, NULL_RTX)
1581 : != NULL_RTX)))
1582 : {
1583 15012 : SET_HARD_REG_SET (OBJECT_CONFLICT_HARD_REGS (obj));
1584 229276128 : SET_HARD_REG_SET (OBJECT_TOTAL_CONFLICT_HARD_REGS (obj));
1585 : }
1586 229276128 : eh_region r;
1587 229276128 : if (can_throw_internal (call)
1588 229276128 : && (r = get_eh_region_from_rtx (call)) != NULL)
1589 3709728 : add_conflict_from_region_landing_pads (r, obj, callee_abi);
1590 229276128 : if (sparseset_bit_p (allocnos_processed, num))
1591 104004524 : continue;
1592 125271604 : sparseset_set_bit (allocnos_processed, num);
1593 :
1594 125271604 : if (allocno_saved_at_call[num] != last_call_num)
1595 : /* Here we are mimicking caller-save.cc behavior
1596 : which does not save hard register at a call if
1597 : it was saved on previous call in the same basic
1598 : block and the hard register was not mentioned
1599 : between the two calls. */
1600 40333276 : ALLOCNO_CALL_FREQ (a) += freq;
1601 : /* Mark it as saved at the next call. */
1602 125271604 : allocno_saved_at_call[num] = last_call_num + 1;
1603 125271604 : ALLOCNO_CALLS_CROSSED_NUM (a)++;
1604 125271604 : ALLOCNO_CROSSED_CALLS_ABIS (a) |= 1 << callee_abi.id ();
1605 125271604 : ALLOCNO_CROSSED_CALLS_CLOBBERED_REGS (a)
1606 125271604 : |= callee_abi.full_and_partial_reg_clobbers ();
1607 125271604 : if (cheap_reg != NULL_RTX
1608 125271604 : && ALLOCNO_REGNO (a) == (int) REGNO (cheap_reg))
1609 33874 : ALLOCNO_CHEAP_CALLS_CROSSED_NUM (a)++;
1610 : }
1611 : }
1612 :
1613 : /* See which defined values die here. Note that we include
1614 : the call insn in the lifetimes of these values, so we don't
1615 : mistakenly consider, for e.g. an addressing mode with a
1616 : side-effect like a post-increment fetching the address,
1617 : that the use happens before the call, and the def to happen
1618 : after the call: we believe both to happen before the actual
1619 : call. (We don't handle return-values here.) */
1620 672971203 : FOR_EACH_INSN_DEF (def, insn)
1621 587341234 : if (!call_p || !DF_REF_FLAGS_IS_SET (def, DF_REF_MAY_CLOBBER))
1622 71801678 : mark_ref_dead (def);
1623 :
1624 85629969 : make_early_clobber_and_input_conflicts ();
1625 :
1626 85629969 : curr_point++;
1627 :
1628 : /* Mark each used value as live. */
1629 188868309 : FOR_EACH_INSN_USE (use, insn)
1630 103238340 : mark_ref_live (use);
1631 :
1632 85629969 : process_single_reg_constrained_operands (true, freq);
1633 :
1634 85629969 : set_p = mark_hard_reg_early_clobbers (insn, true);
1635 :
1636 85629969 : if (set_p)
1637 : {
1638 10813171 : mark_hard_reg_early_clobbers (insn, false);
1639 :
1640 : /* Mark each hard reg as live again. For example, a
1641 : hard register can be in clobber and in an insn
1642 : input. */
1643 26527708 : FOR_EACH_INSN_USE (use, insn)
1644 : {
1645 15714537 : rtx ureg = DF_REF_REG (use);
1646 :
1647 15714537 : if (GET_CODE (ureg) == SUBREG)
1648 341757 : ureg = SUBREG_REG (ureg);
1649 15714537 : if (! REG_P (ureg) || REGNO (ureg) >= FIRST_PSEUDO_REGISTER)
1650 10069136 : continue;
1651 :
1652 5645401 : mark_ref_live (use);
1653 : }
1654 : }
1655 :
1656 85629969 : curr_point++;
1657 : }
1658 14722482 : ignore_reg_for_conflicts = NULL_RTX;
1659 :
1660 14722482 : if (bb_has_eh_pred (bb))
1661 228083 : for (j = 0; ; ++j)
1662 : {
1663 684249 : unsigned int regno = EH_RETURN_DATA_REGNO (j);
1664 456166 : if (regno == INVALID_REGNUM)
1665 : break;
1666 456166 : make_hard_regno_live (regno);
1667 456166 : }
1668 :
1669 : /* Allocnos can't go in stack regs at the start of a basic block
1670 : that is reached by an abnormal edge. Likewise for registers
1671 : that are at least partly call clobbered, because caller-save,
1672 : fixup_abnormal_edges and possibly the table driven EH machinery
1673 : are not quite ready to handle such allocnos live across such
1674 : edges. */
1675 14722482 : if (bb_has_abnormal_pred (bb))
1676 : {
1677 : #ifdef STACK_REGS
1678 719645 : EXECUTE_IF_SET_IN_SPARSESET (objects_live, px)
1679 : {
1680 488993 : ira_allocno_t a = OBJECT_ALLOCNO (ira_object_id_map[px]);
1681 :
1682 488993 : ALLOCNO_NO_STACK_REG_P (a) = true;
1683 488993 : ALLOCNO_TOTAL_NO_STACK_REG_P (a) = true;
1684 : }
1685 2075868 : for (px = FIRST_STACK_REG; px <= LAST_STACK_REG; px++)
1686 1845216 : make_hard_regno_live (px);
1687 : #endif
1688 : /* No need to record conflicts for call clobbered regs if we
1689 : have nonlocal labels around, as we don't ever try to
1690 : allocate such regs in this case. */
1691 230652 : if (!cfun->has_nonlocal_label
1692 230652 : && has_abnormal_call_or_eh_pred_edge_p (bb))
1693 21667030 : for (px = 0; px < FIRST_PSEUDO_REGISTER; px++)
1694 21438956 : if (eh_edge_abi.clobbers_at_least_part_of_reg_p (px)
1695 : #ifdef REAL_PIC_OFFSET_TABLE_REGNUM
1696 : /* We should create a conflict of PIC pseudo with
1697 : PIC hard reg as PIC hard reg can have a wrong
1698 : value after jump described by the abnormal edge.
1699 : In this case we cannot allocate PIC hard reg to
1700 : PIC pseudo as PIC pseudo will also have a wrong
1701 : value. This code is not critical as LRA can fix
1702 : it but it is better to have the right allocation
1703 : earlier. */
1704 21578298 : || (px == REAL_PIC_OFFSET_TABLE_REGNUM
1705 228074 : && pic_offset_table_rtx != NULL_RTX
1706 6305 : && REGNO (pic_offset_table_rtx) >= FIRST_PSEUDO_REGISTER)
1707 : #endif
1708 : )
1709 19432407 : make_hard_regno_live (px);
1710 : }
1711 :
1712 220405995 : EXECUTE_IF_SET_IN_SPARSESET (objects_live, i)
1713 205683513 : make_object_dead (ira_object_id_map[i]);
1714 :
1715 14722482 : curr_point++;
1716 :
1717 : }
1718 : /* Propagate register pressure to upper loop tree nodes. */
1719 16864148 : if (loop_tree_node != ira_loop_tree_root)
1720 75581589 : for (i = 0; i < ira_pressure_classes_num; i++)
1721 : {
1722 60234568 : enum reg_class pclass;
1723 :
1724 60234568 : pclass = ira_pressure_classes[i];
1725 60234568 : if (loop_tree_node->reg_pressure[pclass]
1726 60234568 : > loop_tree_node->parent->reg_pressure[pclass])
1727 4296825 : loop_tree_node->parent->reg_pressure[pclass]
1728 4296825 : = loop_tree_node->reg_pressure[pclass];
1729 : }
1730 16864148 : }
1731 :
1732 : /* Create and set up IRA_START_POINT_RANGES and
1733 : IRA_FINISH_POINT_RANGES. */
1734 : static void
1735 3197522 : create_start_finish_chains (void)
1736 : {
1737 3197522 : ira_object_t obj;
1738 3197522 : ira_object_iterator oi;
1739 3197522 : live_range_t r;
1740 :
1741 3197522 : ira_start_point_ranges
1742 3197522 : = (live_range_t *) ira_allocate (ira_max_point * sizeof (live_range_t));
1743 3197522 : memset (ira_start_point_ranges, 0, ira_max_point * sizeof (live_range_t));
1744 3197522 : ira_finish_point_ranges
1745 3197522 : = (live_range_t *) ira_allocate (ira_max_point * sizeof (live_range_t));
1746 3197522 : memset (ira_finish_point_ranges, 0, ira_max_point * sizeof (live_range_t));
1747 82706591 : FOR_EACH_OBJECT (obj, oi)
1748 187670219 : for (r = OBJECT_LIVE_RANGES (obj); r != NULL; r = r->next)
1749 : {
1750 108161150 : r->start_next = ira_start_point_ranges[r->start];
1751 108161150 : ira_start_point_ranges[r->start] = r;
1752 108161150 : r->finish_next = ira_finish_point_ranges[r->finish];
1753 108161150 : ira_finish_point_ranges[r->finish] = r;
1754 : }
1755 3197522 : }
1756 :
1757 : /* Rebuild IRA_START_POINT_RANGES and IRA_FINISH_POINT_RANGES after
1758 : new live ranges and program points were added as a result if new
1759 : insn generation. */
1760 : void
1761 1680395 : ira_rebuild_start_finish_chains (void)
1762 : {
1763 1680395 : ira_free (ira_finish_point_ranges);
1764 1680395 : ira_free (ira_start_point_ranges);
1765 1680395 : create_start_finish_chains ();
1766 1680395 : }
1767 :
1768 : /* Compress allocno live ranges by removing program points where
1769 : nothing happens. */
1770 : static void
1771 1517127 : remove_some_program_points_and_update_live_ranges (void)
1772 : {
1773 1517127 : unsigned i;
1774 1517127 : int n;
1775 1517127 : int *map;
1776 1517127 : ira_object_t obj;
1777 1517127 : ira_object_iterator oi;
1778 1517127 : live_range_t r, prev_r, next_r;
1779 1517127 : sbitmap_iterator sbi;
1780 1517127 : bool born_p, dead_p, prev_born_p, prev_dead_p;
1781 :
1782 1517127 : auto_sbitmap born (ira_max_point);
1783 1517127 : auto_sbitmap dead (ira_max_point);
1784 1517127 : bitmap_clear (born);
1785 1517127 : bitmap_clear (dead);
1786 36584679 : FOR_EACH_OBJECT (obj, oi)
1787 89592542 : for (r = OBJECT_LIVE_RANGES (obj); r != NULL; r = r->next)
1788 : {
1789 54524990 : ira_assert (r->start <= r->finish);
1790 54524990 : bitmap_set_bit (born, r->start);
1791 54524990 : bitmap_set_bit (dead, r->finish);
1792 : }
1793 :
1794 1517127 : auto_sbitmap born_or_dead (ira_max_point);
1795 1517127 : bitmap_ior (born_or_dead, born, dead);
1796 1517127 : map = (int *) ira_allocate (sizeof (int) * ira_max_point);
1797 1517127 : n = -1;
1798 1517127 : prev_born_p = prev_dead_p = false;
1799 68463872 : EXECUTE_IF_SET_IN_BITMAP (born_or_dead, 0, i, sbi)
1800 : {
1801 65429618 : born_p = bitmap_bit_p (born, i);
1802 65429618 : dead_p = bitmap_bit_p (dead, i);
1803 65429618 : if ((prev_born_p && ! prev_dead_p && born_p && ! dead_p)
1804 59154834 : || (prev_dead_p && ! prev_born_p && dead_p && ! born_p))
1805 16585098 : map[i] = n;
1806 : else
1807 48844520 : map[i] = ++n;
1808 65429618 : prev_born_p = born_p;
1809 65429618 : prev_dead_p = dead_p;
1810 : }
1811 :
1812 1517127 : n++;
1813 1517127 : if (internal_flag_ira_verbose > 1 && ira_dump_file != NULL)
1814 95 : fprintf (ira_dump_file, "Compressing live ranges: from %d to %d - %d%%\n",
1815 95 : ira_max_point, n, 100 * n / ira_max_point);
1816 1517127 : ira_max_point = n;
1817 :
1818 36584679 : FOR_EACH_OBJECT (obj, oi)
1819 89592542 : for (r = OBJECT_LIVE_RANGES (obj), prev_r = NULL; r != NULL; r = next_r)
1820 : {
1821 54524990 : next_r = r->next;
1822 54524990 : r->start = map[r->start];
1823 54524990 : r->finish = map[r->finish];
1824 54524990 : if (prev_r == NULL || prev_r->start > r->finish + 1)
1825 : {
1826 41815018 : prev_r = r;
1827 41815018 : continue;
1828 : }
1829 12709972 : prev_r->start = r->start;
1830 12709972 : prev_r->next = next_r;
1831 12709972 : ira_finish_live_range (r);
1832 : }
1833 :
1834 1517127 : ira_free (map);
1835 1517127 : }
1836 :
1837 : /* Print live ranges R to file F. */
1838 : void
1839 1466 : ira_print_live_range_list (FILE *f, live_range_t r)
1840 : {
1841 3234 : for (; r != NULL; r = r->next)
1842 1768 : fprintf (f, " [%d..%d]", r->start, r->finish);
1843 1466 : fprintf (f, "\n");
1844 1466 : }
1845 :
1846 : DEBUG_FUNCTION void
1847 0 : debug (live_range &ref)
1848 : {
1849 0 : ira_print_live_range_list (stderr, &ref);
1850 0 : }
1851 :
1852 : DEBUG_FUNCTION void
1853 0 : debug (live_range *ptr)
1854 : {
1855 0 : if (ptr)
1856 0 : debug (*ptr);
1857 : else
1858 0 : fprintf (stderr, "<nil>\n");
1859 0 : }
1860 :
1861 : /* Print live ranges R to stderr. */
1862 : void
1863 0 : ira_debug_live_range_list (live_range_t r)
1864 : {
1865 0 : ira_print_live_range_list (stderr, r);
1866 0 : }
1867 :
1868 : /* Print live ranges of object OBJ to file F. */
1869 : static void
1870 1328 : print_object_live_ranges (FILE *f, ira_object_t obj)
1871 : {
1872 0 : ira_print_live_range_list (f, OBJECT_LIVE_RANGES (obj));
1873 0 : }
1874 :
1875 : /* Print live ranges of allocno A to file F. */
1876 : static void
1877 1328 : print_allocno_live_ranges (FILE *f, ira_allocno_t a)
1878 : {
1879 1328 : int n = ALLOCNO_NUM_OBJECTS (a);
1880 1328 : int i;
1881 :
1882 2656 : for (i = 0; i < n; i++)
1883 : {
1884 1328 : fprintf (f, " a%d(r%d", ALLOCNO_NUM (a), ALLOCNO_REGNO (a));
1885 1328 : if (n > 1)
1886 0 : fprintf (f, " [%d]", i);
1887 1328 : fprintf (f, "):");
1888 1328 : print_object_live_ranges (f, ALLOCNO_OBJECT (a, i));
1889 : }
1890 1328 : }
1891 :
1892 : /* Print live ranges of allocno A to stderr. */
1893 : void
1894 0 : ira_debug_allocno_live_ranges (ira_allocno_t a)
1895 : {
1896 0 : print_allocno_live_ranges (stderr, a);
1897 0 : }
1898 :
1899 : /* Print live ranges of all allocnos to file F. */
1900 : static void
1901 190 : print_live_ranges (FILE *f)
1902 : {
1903 190 : ira_allocno_t a;
1904 190 : ira_allocno_iterator ai;
1905 :
1906 1518 : FOR_EACH_ALLOCNO (a, ai)
1907 1328 : print_allocno_live_ranges (f, a);
1908 190 : }
1909 :
1910 : /* Print live ranges of all allocnos to stderr. */
1911 : void
1912 0 : ira_debug_live_ranges (void)
1913 : {
1914 0 : print_live_ranges (stderr);
1915 0 : }
1916 :
1917 : /* The main entry function creates live ranges, set up
1918 : CONFLICT_HARD_REGS and TOTAL_CONFLICT_HARD_REGS for objects, and
1919 : calculate register pressure info. */
1920 : void
1921 1517127 : ira_create_allocno_live_ranges (void)
1922 : {
1923 1517127 : objects_live = sparseset_alloc (ira_objects_num);
1924 1517127 : allocnos_processed = sparseset_alloc (ira_allocnos_num);
1925 1517127 : curr_point = 0;
1926 1517127 : last_call_num = 0;
1927 1517127 : allocno_saved_at_call
1928 1517127 : = (int *) ira_allocate (ira_allocnos_num * sizeof (int));
1929 1517127 : memset (allocno_saved_at_call, 0, ira_allocnos_num * sizeof (int));
1930 1517127 : ira_traverse_loop_tree (true, ira_loop_tree_root, NULL,
1931 : process_bb_node_lives);
1932 1517127 : ira_max_point = curr_point;
1933 1517127 : create_start_finish_chains ();
1934 1517127 : if (internal_flag_ira_verbose > 2 && ira_dump_file != NULL)
1935 95 : print_live_ranges (ira_dump_file);
1936 : /* Clean up. */
1937 1517127 : ira_free (allocno_saved_at_call);
1938 1517127 : sparseset_free (objects_live);
1939 1517127 : sparseset_free (allocnos_processed);
1940 1517127 : }
1941 :
1942 : /* Compress allocno live ranges. */
1943 : void
1944 1517127 : ira_compress_allocno_live_ranges (void)
1945 : {
1946 1517127 : remove_some_program_points_and_update_live_ranges ();
1947 1517127 : ira_rebuild_start_finish_chains ();
1948 1517127 : if (internal_flag_ira_verbose > 2 && ira_dump_file != NULL)
1949 : {
1950 95 : fprintf (ira_dump_file, "Ranges after the compression:\n");
1951 95 : print_live_ranges (ira_dump_file);
1952 : }
1953 1517127 : }
1954 :
1955 : /* Free arrays IRA_START_POINT_RANGES and IRA_FINISH_POINT_RANGES. */
1956 : void
1957 1517127 : ira_finish_allocno_live_ranges (void)
1958 : {
1959 1517127 : ira_free (ira_finish_point_ranges);
1960 1517127 : ira_free (ira_start_point_ranges);
1961 1517127 : }
|