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 37521280 : make_hard_regno_live (int regno)
98 : {
99 37521280 : SET_HARD_REG_BIT (hard_regs_live, regno);
100 35391696 : }
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 16282712 : make_hard_regno_dead (int regno)
106 : {
107 16282712 : unsigned int i;
108 279815228 : EXECUTE_IF_SET_IN_SPARSESET (objects_live, i)
109 : {
110 263532516 : ira_object_t obj = ira_object_id_map[i];
111 :
112 265157214 : if (ignore_reg_for_conflicts != NULL_RTX
113 172701436 : && REGNO (ignore_reg_for_conflicts)
114 172701436 : == (unsigned int) ALLOCNO_REGNO (OBJECT_ALLOCNO (obj)))
115 1624698 : continue;
116 :
117 261907818 : SET_HARD_REG_BIT (OBJECT_CONFLICT_HARD_REGS (obj), regno);
118 261907818 : SET_HARD_REG_BIT (OBJECT_TOTAL_CONFLICT_HARD_REGS (obj), regno);
119 : }
120 16282712 : CLEAR_HARD_REG_BIT (hard_regs_live, regno);
121 16282712 : }
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 241730490 : make_object_live (ira_object_t obj)
127 : {
128 241730490 : sparseset_set_bit (objects_live, OBJECT_CONFLICT_ID (obj));
129 :
130 241730490 : live_range_t lr = OBJECT_LIVE_RANGES (obj);
131 241730490 : if (lr == NULL
132 205233431 : || (lr->finish != curr_point && lr->finish + 1 != curr_point))
133 54324436 : ira_add_live_range_to_object (obj, curr_point, -1);
134 241730490 : }
135 :
136 : /* Update ALLOCNO_EXCESS_PRESSURE_POINTS_NUM for the allocno
137 : associated with object OBJ. */
138 : static void
139 248985829 : update_allocno_pressure_excess_length (ira_object_t obj)
140 : {
141 248985829 : ira_allocno_t a = OBJECT_ALLOCNO (obj);
142 248985829 : int start, i;
143 248985829 : enum reg_class aclass, pclass, cl;
144 248985829 : live_range_t p;
145 :
146 248985829 : aclass = ALLOCNO_CLASS (a);
147 248985829 : pclass = ira_pressure_class_translate[aclass];
148 2445701588 : for (i = 0;
149 2445701588 : (cl = ira_reg_class_super_classes[pclass][i]) != LIM_REG_CLASSES;
150 : i++)
151 : {
152 2196715759 : if (! ira_reg_pressure_class_p[cl])
153 1952540557 : continue;
154 244175202 : if (high_pressure_start_point[cl] < 0)
155 73720525 : continue;
156 170454677 : p = OBJECT_LIVE_RANGES (obj);
157 170454677 : ira_assert (p != NULL);
158 170454677 : start = (high_pressure_start_point[cl] > p->start
159 170454677 : ? high_pressure_start_point[cl] : p->start);
160 170454677 : ALLOCNO_EXCESS_PRESSURE_POINTS_NUM (a) += curr_point - start + 1;
161 : }
162 248985829 : }
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 241730490 : make_object_dead (ira_object_t obj)
168 : {
169 241730490 : live_range_t lr;
170 241730490 : int regno;
171 241730490 : int ignore_regno = -1;
172 241730490 : int ignore_total_regno = -1;
173 241730490 : int end_regno = -1;
174 :
175 241730490 : 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 241730490 : if (ignore_reg_for_conflicts != NULL_RTX
180 241730490 : && REGNO (ignore_reg_for_conflicts) < FIRST_PSEUDO_REGISTER)
181 : {
182 3421503 : end_regno = END_REGNO (ignore_reg_for_conflicts);
183 3421503 : ignore_regno = ignore_total_regno = REGNO (ignore_reg_for_conflicts);
184 :
185 6843006 : for (regno = ignore_regno; regno < end_regno; regno++)
186 : {
187 3421503 : if (TEST_HARD_REG_BIT (OBJECT_CONFLICT_HARD_REGS (obj), regno))
188 524482 : ignore_regno = end_regno;
189 3421503 : if (TEST_HARD_REG_BIT (OBJECT_TOTAL_CONFLICT_HARD_REGS (obj), regno))
190 524482 : ignore_total_regno = end_regno;
191 : }
192 : }
193 :
194 966921960 : OBJECT_CONFLICT_HARD_REGS (obj) |= hard_regs_live;
195 244627511 : 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 244627511 : for (regno = ignore_regno; regno < end_regno; regno++)
200 2897021 : CLEAR_HARD_REG_BIT (OBJECT_CONFLICT_HARD_REGS (obj), regno);
201 244627511 : for (regno = ignore_total_regno; regno < end_regno; regno++)
202 2897021 : CLEAR_HARD_REG_BIT (OBJECT_TOTAL_CONFLICT_HARD_REGS (obj), regno);
203 :
204 241730490 : lr = OBJECT_LIVE_RANGES (obj);
205 241730490 : ira_assert (lr != NULL);
206 241730490 : lr->finish = curr_point;
207 241730490 : update_allocno_pressure_excess_length (obj);
208 241730490 : }
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 259561751 : inc_register_pressure (enum reg_class pclass, int n)
220 : {
221 259561751 : int i;
222 259561751 : enum reg_class cl;
223 :
224 2544888297 : for (i = 0;
225 2544888297 : (cl = ira_reg_class_super_classes[pclass][i]) != LIM_REG_CLASSES;
226 : i++)
227 : {
228 2285326546 : if (! ira_reg_pressure_class_p[cl])
229 2030322244 : continue;
230 255004302 : curr_reg_pressure[cl] += n;
231 255004302 : if (high_pressure_start_point[cl] < 0
232 106117314 : && (curr_reg_pressure[cl] > ira_class_hard_regs_num[cl]))
233 1750706 : high_pressure_start_point[cl] = curr_point;
234 255004302 : if (curr_bb_node->reg_pressure[cl] < curr_reg_pressure[cl])
235 219652336 : curr_bb_node->reg_pressure[cl] = curr_reg_pressure[cl];
236 : }
237 259561751 : }
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 53331010 : dec_register_pressure (enum reg_class pclass, int nregs)
246 : {
247 53331010 : int i;
248 53331010 : unsigned int j;
249 53331010 : enum reg_class cl;
250 53331010 : bool set_p = false;
251 :
252 53331010 : for (i = 0;
253 513926008 : (cl = ira_reg_class_super_classes[pclass][i]) != LIM_REG_CLASSES;
254 : i++)
255 : {
256 460594998 : if (! ira_reg_pressure_class_p[cl])
257 407754022 : continue;
258 52840976 : curr_reg_pressure[cl] -= nregs;
259 52840976 : ira_assert (curr_reg_pressure[cl] >= 0);
260 52840976 : if (high_pressure_start_point[cl] >= 0
261 4582009 : && curr_reg_pressure[cl] <= ira_class_hard_regs_num[cl])
262 460594998 : set_p = true;
263 : }
264 53331010 : if (set_p)
265 : {
266 7730941 : EXECUTE_IF_SET_IN_SPARSESET (objects_live, j)
267 7255339 : update_allocno_pressure_excess_length (ira_object_id_map[j]);
268 4517573 : for (i = 0;
269 4993175 : (cl = ira_reg_class_super_classes[pclass][i]) != LIM_REG_CLASSES;
270 : i++)
271 : {
272 4517573 : if (! ira_reg_pressure_class_p[cl])
273 4041971 : continue;
274 475602 : if (high_pressure_start_point[cl] >= 0
275 475602 : && curr_reg_pressure[cl] <= ira_class_hard_regs_num[cl])
276 475602 : high_pressure_start_point[cl] = -1;
277 : }
278 : }
279 53331010 : }
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 116169 : pseudo_regno_single_word_and_live_p (int regno)
285 : {
286 116169 : ira_allocno_t a = ira_curr_regno_allocno_map[regno];
287 116169 : ira_object_t obj;
288 :
289 116169 : if (a == NULL)
290 : return false;
291 116169 : if (ALLOCNO_NUM_OBJECTS (a) > 1)
292 : return false;
293 :
294 116169 : obj = ALLOCNO_OBJECT (a, 0);
295 :
296 116169 : 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 226087253 : mark_pseudo_regno_live (int regno)
303 : {
304 226087253 : ira_allocno_t a = ira_curr_regno_allocno_map[regno];
305 226087253 : enum reg_class pclass;
306 226087253 : int i, n, nregs;
307 :
308 226087253 : if (a == NULL)
309 : return;
310 :
311 : /* Invalidate because it is referenced. */
312 226087253 : allocno_saved_at_call[ALLOCNO_NUM (a)] = 0;
313 :
314 226087253 : n = ALLOCNO_NUM_OBJECTS (a);
315 226087253 : pclass = ira_pressure_class_translate[ALLOCNO_CLASS (a)];
316 226087253 : nregs = ira_reg_class_max_nregs[ALLOCNO_CLASS (a)][ALLOCNO_MODE (a)];
317 226087253 : if (n > 1)
318 : {
319 : /* We track every subobject separately. */
320 69725772 : gcc_assert (nregs == n);
321 : nregs = 1;
322 : }
323 :
324 521900278 : for (i = 0; i < n; i++)
325 : {
326 295813025 : ira_object_t obj = ALLOCNO_OBJECT (a, i);
327 :
328 295813025 : if (sparseset_bit_p (objects_live, OBJECT_CONFLICT_ID (obj)))
329 54396153 : continue;
330 :
331 241416872 : inc_register_pressure (pclass, nregs);
332 241416872 : 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 831652 : mark_pseudo_regno_subword_live (int regno, int subword)
341 : {
342 831652 : ira_allocno_t a = ira_curr_regno_allocno_map[regno];
343 831652 : int n;
344 831652 : enum reg_class pclass;
345 831652 : ira_object_t obj;
346 :
347 831652 : if (a == NULL)
348 : return;
349 :
350 : /* Invalidate because it is referenced. */
351 831652 : allocno_saved_at_call[ALLOCNO_NUM (a)] = 0;
352 :
353 831652 : n = ALLOCNO_NUM_OBJECTS (a);
354 831652 : if (n == 1)
355 : {
356 37915 : mark_pseudo_regno_live (regno);
357 37915 : return;
358 : }
359 :
360 793737 : pclass = ira_pressure_class_translate[ALLOCNO_CLASS (a)];
361 793737 : gcc_assert
362 : (n == ira_reg_class_max_nregs[ALLOCNO_CLASS (a)][ALLOCNO_MODE (a)]);
363 793737 : obj = ALLOCNO_OBJECT (a, subword);
364 :
365 793737 : if (sparseset_bit_p (objects_live, OBJECT_CONFLICT_ID (obj)))
366 : return;
367 :
368 313618 : inc_register_pressure (pclass, 1);
369 313618 : 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 103712072 : mark_hard_reg_live (rtx reg)
377 : {
378 103712072 : int regno = REGNO (reg);
379 :
380 103712072 : if (! TEST_HARD_REG_BIT (ira_no_alloc_regs, regno))
381 : {
382 32530231 : int last = END_REGNO (reg);
383 32530231 : enum reg_class aclass, pclass;
384 :
385 65060462 : while (regno < last)
386 : {
387 32530231 : if (! TEST_HARD_REG_BIT (hard_regs_live, regno)
388 32530231 : && ! TEST_HARD_REG_BIT (eliminable_regset, regno))
389 : {
390 17831261 : aclass = ira_hard_regno_allocno_class[regno];
391 17831261 : pclass = ira_pressure_class_translate[aclass];
392 17831261 : inc_register_pressure (pclass, 1);
393 17831261 : make_hard_regno_live (regno);
394 : }
395 32530231 : regno++;
396 : }
397 : }
398 103712072 : }
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 86550621 : mark_pseudo_reg_live (rtx orig_reg, unsigned regno)
405 : {
406 86550621 : if (read_modify_subreg_p (orig_reg))
407 : {
408 1239736 : mark_pseudo_regno_subword_live (regno,
409 831652 : subreg_lowpart_p (orig_reg) ? 0 : 1);
410 : }
411 : else
412 85718969 : mark_pseudo_regno_live (regno);
413 86550621 : }
414 :
415 : /* Mark the register referenced by use or def REF as live. */
416 : static void
417 188471755 : mark_ref_live (df_ref ref)
418 : {
419 188471755 : rtx reg = DF_REF_REG (ref);
420 188471755 : rtx orig_reg = reg;
421 :
422 188471755 : if (GET_CODE (reg) == SUBREG)
423 2865992 : reg = SUBREG_REG (reg);
424 :
425 188471755 : if (REGNO (reg) >= FIRST_PSEUDO_REGISTER)
426 84759683 : mark_pseudo_reg_live (orig_reg, REGNO (reg));
427 : else
428 103712072 : mark_hard_reg_live (reg);
429 188471755 : }
430 :
431 : /* Mark the pseudo register REGNO as dead. Update all information about
432 : live ranges and register pressure. */
433 : static void
434 35458267 : mark_pseudo_regno_dead (int regno)
435 : {
436 35458267 : ira_allocno_t a = ira_curr_regno_allocno_map[regno];
437 35458267 : int n, i, nregs;
438 35458267 : enum reg_class cl;
439 :
440 35458267 : if (a == NULL)
441 : return;
442 :
443 : /* Invalidate because it is referenced. */
444 35458267 : allocno_saved_at_call[ALLOCNO_NUM (a)] = 0;
445 :
446 35458267 : n = ALLOCNO_NUM_OBJECTS (a);
447 35458267 : cl = ira_pressure_class_translate[ALLOCNO_CLASS (a)];
448 35458267 : nregs = ira_reg_class_max_nregs[ALLOCNO_CLASS (a)][ALLOCNO_MODE (a)];
449 35458267 : if (n > 1)
450 : {
451 : /* We track every subobject separately. */
452 1265891 : gcc_assert (nregs == n);
453 : nregs = 1;
454 : }
455 72182425 : for (i = 0; i < n; i++)
456 : {
457 36724158 : ira_object_t obj = ALLOCNO_OBJECT (a, i);
458 36724158 : if (!sparseset_bit_p (objects_live, OBJECT_CONFLICT_ID (obj)))
459 3511 : continue;
460 :
461 36720647 : dec_register_pressure (cl, nregs);
462 36720647 : 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 331781 : mark_pseudo_regno_subword_dead (int regno, int subword)
470 : {
471 331781 : ira_allocno_t a = ira_curr_regno_allocno_map[regno];
472 331781 : int n;
473 331781 : enum reg_class cl;
474 331781 : ira_object_t obj;
475 :
476 331781 : if (a == NULL)
477 : return;
478 :
479 : /* Invalidate because it is referenced. */
480 331781 : allocno_saved_at_call[ALLOCNO_NUM (a)] = 0;
481 :
482 331781 : n = ALLOCNO_NUM_OBJECTS (a);
483 331781 : if (n == 1)
484 : /* The allocno as a whole doesn't die in this case. */
485 : return;
486 :
487 327651 : cl = ira_pressure_class_translate[ALLOCNO_CLASS (a)];
488 327651 : gcc_assert
489 : (n == ira_reg_class_max_nregs[ALLOCNO_CLASS (a)][ALLOCNO_MODE (a)]);
490 :
491 327651 : obj = ALLOCNO_OBJECT (a, subword);
492 327651 : if (!sparseset_bit_p (objects_live, OBJECT_CONFLICT_ID (obj)))
493 : return;
494 :
495 327651 : dec_register_pressure (cl, 1);
496 327651 : 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 47940427 : mark_hard_reg_dead (rtx reg)
503 : {
504 47940427 : int regno = REGNO (reg);
505 :
506 47940427 : if (! TEST_HARD_REG_BIT (ira_no_alloc_regs, regno))
507 : {
508 16284730 : int last = END_REGNO (reg);
509 16284730 : enum reg_class aclass, pclass;
510 :
511 32569460 : while (regno < last)
512 : {
513 16284730 : if (TEST_HARD_REG_BIT (hard_regs_live, regno))
514 : {
515 16282712 : aclass = ira_hard_regno_allocno_class[regno];
516 16282712 : pclass = ira_pressure_class_translate[aclass];
517 16282712 : dec_register_pressure (pclass, 1);
518 16282712 : make_hard_regno_dead (regno);
519 : }
520 16284730 : regno++;
521 : }
522 : }
523 47940427 : }
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 35790048 : mark_pseudo_reg_dead (rtx orig_reg, unsigned regno)
530 : {
531 35790048 : if (read_modify_subreg_p (orig_reg))
532 : {
533 498151 : mark_pseudo_regno_subword_dead (regno,
534 331781 : subreg_lowpart_p (orig_reg) ? 0 : 1);
535 : }
536 : else
537 35458267 : mark_pseudo_regno_dead (regno);
538 35790048 : }
539 :
540 : /* Mark the register referenced by definition DEF as dead, if the
541 : definition is a total one. */
542 : static void
543 81943685 : mark_ref_dead (df_ref def)
544 : {
545 81943685 : rtx reg = DF_REF_REG (def);
546 81943685 : rtx orig_reg = reg;
547 :
548 81943685 : if (DF_REF_FLAGS_IS_SET (def, DF_REF_CONDITIONAL))
549 : return;
550 :
551 81943685 : if (GET_CODE (reg) == SUBREG)
552 855981 : reg = SUBREG_REG (reg);
553 :
554 81943685 : if (DF_REF_FLAGS_IS_SET (def, DF_REF_PARTIAL)
555 81943685 : && (GET_CODE (orig_reg) != SUBREG
556 321965 : || REGNO (reg) < FIRST_PSEUDO_REGISTER
557 321965 : || !read_modify_subreg_p (orig_reg)))
558 4148 : return;
559 :
560 81939537 : if (REGNO (reg) >= FIRST_PSEUDO_REGISTER)
561 33999110 : mark_pseudo_reg_dead (orig_reg, REGNO (reg));
562 : else
563 47940427 : 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 2776144 : make_pseudo_conflict (rtx reg, enum reg_class cl, rtx dreg, rtx orig_dreg,
574 : bool advance_p)
575 : {
576 2776144 : rtx orig_reg = reg;
577 2776144 : ira_allocno_t a;
578 :
579 2776144 : if (GET_CODE (reg) == SUBREG)
580 73774 : reg = SUBREG_REG (reg);
581 :
582 2776144 : if (! REG_P (reg) || REGNO (reg) < FIRST_PSEUDO_REGISTER)
583 : return advance_p;
584 :
585 985356 : a = ira_curr_regno_allocno_map[REGNO (reg)];
586 985356 : if (! reg_classes_intersect_p (cl, ALLOCNO_CLASS (a)))
587 : return advance_p;
588 :
589 895469 : if (advance_p)
590 850931 : curr_point++;
591 :
592 895469 : mark_pseudo_reg_live (orig_reg, REGNO (reg));
593 895469 : mark_pseudo_reg_live (orig_dreg, REGNO (dreg));
594 895469 : mark_pseudo_reg_dead (orig_reg, REGNO (reg));
595 895469 : mark_pseudo_reg_dead (orig_dreg, REGNO (dreg));
596 :
597 895469 : 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 2822502 : 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 2822502 : if (! reg_classes_intersect_p (def_cl, use_cl))
612 : return advance_p;
613 :
614 2760623 : 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 2760623 : if (use < recog_data.n_operands - 1
624 1039587 : && recog_data.constraints[use][0] == '%')
625 6469 : advance_p
626 6469 : = make_pseudo_conflict (recog_data.operand[use + 1],
627 : use_cl, dreg, orig_dreg, advance_p);
628 2760623 : if (use >= 1
629 2760377 : && recog_data.constraints[use - 1][0] == '%')
630 9052 : advance_p
631 9052 : = 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 14175780 : check_and_make_def_conflict (int alt, int def, enum reg_class def_cl,
659 : bool for_tie_p)
660 : {
661 14175780 : int use, use_match;
662 14175780 : ira_allocno_t a;
663 14175780 : enum reg_class use_cl, acl;
664 14175780 : bool advance_p;
665 14175780 : rtx dreg = recog_data.operand[def];
666 14175780 : rtx orig_dreg = dreg;
667 :
668 14175780 : if (def_cl == NO_REGS)
669 : return;
670 :
671 14175780 : if (GET_CODE (dreg) == SUBREG)
672 110455 : dreg = SUBREG_REG (dreg);
673 :
674 14175780 : if (! REG_P (dreg) || REGNO (dreg) < FIRST_PSEUDO_REGISTER)
675 : return;
676 :
677 11976078 : a = ira_curr_regno_allocno_map[REGNO (dreg)];
678 11976078 : acl = ALLOCNO_CLASS (a);
679 11976078 : if (! reg_classes_intersect_p (acl, def_cl))
680 : return;
681 :
682 11782135 : advance_p = true;
683 :
684 11782135 : int n_operands = recog_data.n_operands;
685 11782135 : const operand_alternative *op_alt = &recog_op_alt[alt * n_operands];
686 48737217 : for (use = 0; use < n_operands; use++)
687 : {
688 36955082 : int alt1;
689 :
690 36955082 : if (use == def || recog_data.operand_type[use] == OP_OUT)
691 11927812 : 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 36743029 : if (op_alt[use].matches == def
701 25027270 : || (for_tie_p
702 13079182 : && rtx_equal_p (recog_data.operand[use],
703 13079182 : recog_data.operand[op_alt[def].matched])))
704 11715759 : continue;
705 :
706 13311511 : if (op_alt[use].anything_ok)
707 : use_cl = ALL_REGS;
708 : else
709 11711250 : use_cl = op_alt[use].cl;
710 11711250 : if (use_cl == NO_REGS)
711 4734884 : 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 8576627 : if (for_tie_p && targetm.class_likely_spilled_p (use_cl))
718 973251 : 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 19228629 : for (alt1 = 0; alt1 < recog_data.n_alternatives; alt1++)
728 : {
729 16406128 : if (!TEST_BIT (preferred_alternatives, alt1))
730 7383014 : continue;
731 9023114 : const operand_alternative *op_alt1
732 9023114 : = &recog_op_alt[alt1 * n_operands];
733 9023114 : if (op_alt1[use].matches == def
734 7269627 : || (use < n_operands - 1
735 2652359 : && recog_data.constraints[use][0] == '%'
736 8125 : && op_alt1[use + 1].matches == def)
737 7269627 : || (use >= 1
738 7268159 : && recog_data.constraints[use - 1][0] == '%'
739 3032701 : && op_alt1[use - 1].matches == def))
740 : break;
741 4247634 : if (for_tie_p
742 4048627 : && !op_alt1[def].earlyclobber
743 4047467 : && op_alt1[def].matched < 0
744 21764 : && alternative_class (op_alt1, def) != NO_REGS
745 4269398 : && alternative_class (op_alt1, use) != NO_REGS)
746 : break;
747 : }
748 :
749 7603376 : if (alt1 < recog_data.n_alternatives)
750 4780875 : continue;
751 :
752 2822501 : advance_p = check_and_make_def_use_conflict (dreg, orig_dreg, def_cl,
753 : use, use_cl, advance_p);
754 :
755 2822501 : 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 83175472 : make_early_clobber_and_input_conflicts (void)
779 : {
780 83175472 : int alt;
781 83175472 : int def, def_match;
782 83175472 : enum reg_class def_cl;
783 :
784 83175472 : int n_alternatives = recog_data.n_alternatives;
785 83175472 : int n_operands = recog_data.n_operands;
786 83175472 : const operand_alternative *op_alt = recog_op_alt;
787 1131485297 : for (alt = 0; alt < n_alternatives; alt++, op_alt += n_operands)
788 1048309825 : if (TEST_BIT (preferred_alternatives, alt))
789 383479376 : for (def = 0; def < n_operands; def++)
790 : {
791 264644195 : if (op_alt[def].anything_ok)
792 : def_cl = ALL_REGS;
793 : else
794 250790908 : def_cl = op_alt[def].cl;
795 250790908 : if (def_cl != NO_REGS)
796 : {
797 209467611 : if (op_alt[def].earlyclobber)
798 129675 : check_and_make_def_conflict (alt, def, def_cl, false);
799 209337936 : else if (op_alt[def].matched >= 0
800 209337936 : && !targetm.class_likely_spilled_p (def_cl))
801 14010068 : check_and_make_def_conflict (alt, def, def_cl, true);
802 : }
803 :
804 264644195 : if ((def_match = op_alt[def].matches) >= 0
805 264644195 : && (op_alt[def_match].earlyclobber
806 14674918 : || op_alt[def].earlyclobber))
807 : {
808 36037 : if (op_alt[def_match].anything_ok)
809 : def_cl = ALL_REGS;
810 : else
811 36037 : def_cl = op_alt[def_match].cl;
812 36037 : check_and_make_def_conflict (alt, def, def_cl, false);
813 : }
814 : }
815 83175472 : }
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 93765425 : mark_hard_reg_early_clobbers (rtx_insn *insn, bool live_p)
821 : {
822 93765425 : df_ref def;
823 93765425 : bool set_p = false;
824 :
825 674849399 : FOR_EACH_INSN_DEF (def, insn)
826 581083974 : if (DF_REF_FLAGS_IS_SET (def, DF_REF_MUST_CLOBBER))
827 : {
828 23076775 : rtx dreg = DF_REF_REG (def);
829 :
830 23076775 : if (GET_CODE (dreg) == SUBREG)
831 0 : dreg = SUBREG_REG (dreg);
832 23076775 : if (! REG_P (dreg) || REGNO (dreg) >= FIRST_PSEUDO_REGISTER)
833 140657 : 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 22936118 : if (live_p)
839 11468059 : mark_ref_live (def);
840 : else
841 11468059 : mark_ref_dead (def);
842 : set_p = true;
843 : }
844 :
845 93765425 : 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 175749134 : single_reg_class (const char *constraints, rtx op, rtx equiv_const)
853 : {
854 175749134 : int c;
855 175749134 : enum reg_class cl, next_cl;
856 175749134 : enum constraint_num cn;
857 :
858 175749134 : cl = NO_REGS;
859 175749134 : alternative_mask preferred = preferred_alternatives;
860 913541777 : while ((c = *constraints))
861 : {
862 899823224 : if (c == '#')
863 0 : preferred &= ~ALTERNATIVE_BIT (0);
864 899823224 : else if (c == ',')
865 246017744 : preferred >>= 1;
866 653805480 : else if (preferred & 1)
867 198121689 : switch (c)
868 : {
869 : case 'g':
870 : return NO_REGS;
871 :
872 178322659 : default:
873 : /* ??? Is this the best way to handle memory constraints? */
874 178322659 : cn = lookup_constraint (constraints);
875 178322659 : if (insn_extra_memory_constraint (cn)
876 166356892 : || insn_extra_special_memory_constraint (cn)
877 : || insn_extra_relaxed_memory_constraint (cn)
878 344679549 : || insn_extra_address_constraint (cn))
879 : return NO_REGS;
880 165767267 : if (constraint_satisfied_p (op, cn)
881 165767267 : || (equiv_const != NULL_RTX
882 0 : && CONSTANT_P (equiv_const)
883 0 : && constraint_satisfied_p (equiv_const, cn)))
884 14478222 : return NO_REGS;
885 151289045 : next_cl = reg_class_for_constraint (cn);
886 120317236 : if (next_cl == NO_REGS)
887 : break;
888 117109886 : if (cl == NO_REGS
889 117109886 : ? ira_class_singleton[next_cl][GET_MODE (op)] < 0
890 985868 : : (ira_class_singleton[cl][GET_MODE (op)]
891 985868 : != ira_class_singleton[next_cl][GET_MODE (op)]))
892 : return NO_REGS;
893 : cl = next_cl;
894 : break;
895 :
896 12709203 : case '0': case '1': case '2': case '3': case '4':
897 12709203 : case '5': case '6': case '7': case '8': case '9':
898 12709203 : {
899 12709203 : char *end;
900 12709203 : unsigned long dup = strtoul (constraints, &end, 10);
901 12709203 : constraints = end;
902 12709203 : next_cl
903 12709203 : = single_reg_class (recog_data.constraints[dup],
904 : recog_data.operand[dup], NULL_RTX);
905 12709203 : if (cl == NO_REGS
906 12709203 : ? ira_class_singleton[next_cl][GET_MODE (op)] < 0
907 15573 : : (ira_class_singleton[cl][GET_MODE (op)]
908 15573 : != ira_class_singleton[next_cl][GET_MODE (op)]))
909 12501118 : return NO_REGS;
910 208085 : cl = next_cl;
911 208085 : continue;
912 208085 : }
913 : }
914 737584558 : 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 178157215 : single_reg_operand_class (int op_num)
924 : {
925 178157215 : if (op_num < 0 || recog_data.n_alternatives == 0)
926 : return NO_REGS;
927 163039931 : return single_reg_class (recog_data.constraints[op_num],
928 163039931 : 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 27251 : ira_implicitly_set_insn_hard_regs (HARD_REG_SET *set,
936 : alternative_mask preferred)
937 : {
938 27251 : int i, c, regno = 0;
939 27251 : enum reg_class cl;
940 27251 : rtx op;
941 27251 : machine_mode mode;
942 :
943 27251 : CLEAR_HARD_REG_SET (*set);
944 85564 : for (i = 0; i < recog_data.n_operands; i++)
945 : {
946 58313 : op = recog_data.operand[i];
947 :
948 58313 : if (GET_CODE (op) == SUBREG)
949 1264 : op = SUBREG_REG (op);
950 :
951 58313 : if (GET_CODE (op) == SCRATCH
952 58313 : || (REG_P (op) && (regno = REGNO (op)) >= FIRST_PSEUDO_REGISTER))
953 : {
954 39772 : const char *p = recog_data.constraints[i];
955 :
956 79544 : mode = (GET_CODE (op) == SCRATCH
957 39772 : ? GET_MODE (op) : PSEUDO_REGNO_MODE (regno));
958 39772 : cl = NO_REGS;
959 1427985 : for (; (c = *p); p += CONSTRAINT_LEN (c, p))
960 1388213 : if (c == '#')
961 0 : preferred &= ~ALTERNATIVE_BIT (0);
962 1388213 : else if (c == ',')
963 469378 : preferred >>= 1;
964 918835 : else if (preferred & 1)
965 : {
966 699889 : cl = reg_class_for_constraint (lookup_constraint (p));
967 307773 : if (cl != NO_REGS)
968 : {
969 : /* There is no register pressure problem if all of the
970 : regs in this class are fixed. */
971 280405 : int regno = ira_class_singleton[cl][mode];
972 280405 : if (regno >= 0)
973 2008 : add_to_hard_reg_set (set, mode, regno);
974 : }
975 419484 : else if (c == '{')
976 : {
977 0 : int regno = decode_hard_reg_constraint (p);
978 0 : gcc_assert (regno >= 0 && regno < FIRST_PSEUDO_REGISTER);
979 0 : add_to_hard_reg_set (set, mode, regno);
980 : }
981 : }
982 : }
983 : }
984 27251 : }
985 : /* Processes input operands, if IN_P, or output operands otherwise of
986 : the current insn with FREQ to find allocno which can use only one
987 : hard register and makes other currently living allocnos conflicting
988 : with the hard register. */
989 : static void
990 166350944 : process_single_reg_class_operands (bool in_p, int freq)
991 : {
992 166350944 : int i, regno;
993 166350944 : unsigned int px;
994 166350944 : enum reg_class cl;
995 166350944 : rtx operand;
996 166350944 : ira_allocno_t operand_a, a;
997 :
998 522506076 : for (i = 0; i < recog_data.n_operands; i++)
999 : {
1000 356155132 : operand = recog_data.operand[i];
1001 356155132 : if (in_p && recog_data.operand_type[i] != OP_IN
1002 60676998 : && recog_data.operand_type[i] != OP_INOUT)
1003 60597349 : continue;
1004 178077566 : if (! in_p && recog_data.operand_type[i] != OP_OUT
1005 117480217 : && recog_data.operand_type[i] != OP_INOUT)
1006 117400568 : continue;
1007 178157215 : cl = single_reg_operand_class (i);
1008 178157215 : if (cl == NO_REGS)
1009 177455050 : continue;
1010 :
1011 702165 : operand_a = NULL;
1012 :
1013 702165 : if (GET_CODE (operand) == SUBREG)
1014 56625 : operand = SUBREG_REG (operand);
1015 :
1016 702165 : if (REG_P (operand)
1017 702165 : && (regno = REGNO (operand)) >= FIRST_PSEUDO_REGISTER)
1018 : {
1019 697865 : enum reg_class aclass;
1020 :
1021 697865 : operand_a = ira_curr_regno_allocno_map[regno];
1022 697865 : aclass = ALLOCNO_CLASS (operand_a);
1023 697865 : if (ira_class_subset_p[cl][aclass])
1024 : {
1025 : /* View the desired allocation of OPERAND as:
1026 :
1027 : (REG:YMODE YREGNO),
1028 :
1029 : a simplification of:
1030 :
1031 : (subreg:YMODE (reg:XMODE XREGNO) OFFSET). */
1032 692576 : machine_mode ymode, xmode;
1033 692576 : int xregno, yregno;
1034 692576 : poly_int64 offset;
1035 :
1036 692576 : xmode = recog_data.operand_mode[i];
1037 692576 : xregno = ira_class_singleton[cl][xmode];
1038 692576 : gcc_assert (xregno >= 0);
1039 692576 : ymode = ALLOCNO_MODE (operand_a);
1040 692576 : offset = subreg_lowpart_offset (ymode, xmode);
1041 692576 : yregno = simplify_subreg_regno (xregno, xmode, offset, ymode);
1042 692576 : if (yregno >= 0
1043 692576 : && ira_class_hard_reg_index[aclass][yregno] >= 0)
1044 : {
1045 692576 : int cost;
1046 :
1047 692576 : ira_allocate_and_set_costs
1048 692576 : (&ALLOCNO_CONFLICT_HARD_REG_COSTS (operand_a),
1049 : aclass, 0);
1050 692576 : ira_init_register_move_cost_if_necessary (xmode);
1051 1385152 : cost = freq * (in_p
1052 692576 : ? ira_register_move_cost[xmode][aclass][cl]
1053 402102 : : ira_register_move_cost[xmode][cl][aclass]);
1054 692576 : ALLOCNO_CONFLICT_HARD_REG_COSTS (operand_a)
1055 692576 : [ira_class_hard_reg_index[aclass][yregno]] -= cost;
1056 : }
1057 : }
1058 : }
1059 :
1060 28997263 : EXECUTE_IF_SET_IN_SPARSESET (objects_live, px)
1061 : {
1062 28295098 : ira_object_t obj = ira_object_id_map[px];
1063 28295098 : a = OBJECT_ALLOCNO (obj);
1064 28295098 : if (a != operand_a)
1065 : {
1066 : /* We could increase costs of A instead of making it
1067 : conflicting with the hard register. But it works worse
1068 : because it will be spilled in reload in anyway. */
1069 110249796 : OBJECT_CONFLICT_HARD_REGS (obj) |= reg_class_contents[cl];
1070 28295098 : OBJECT_TOTAL_CONFLICT_HARD_REGS (obj) |= reg_class_contents[cl];
1071 : }
1072 : }
1073 : }
1074 166350944 : }
1075 :
1076 : /* Go through the operands of the extracted insn looking for operand
1077 : alternatives that apply a register filter. Record any such filters
1078 : in the operand's allocno. */
1079 : static void
1080 83175472 : process_register_constraint_filters ()
1081 : {
1082 261253038 : for (int opno = 0; opno < recog_data.n_operands; ++opno)
1083 : {
1084 178077566 : rtx op = recog_data.operand[opno];
1085 178077566 : if (SUBREG_P (op))
1086 2827735 : op = SUBREG_REG (op);
1087 178077566 : if (REG_P (op) && !HARD_REGISTER_P (op))
1088 : {
1089 73555413 : ira_allocno_t a = ira_curr_regno_allocno_map[REGNO (op)];
1090 1027493178 : for (int alt = 0; alt < recog_data.n_alternatives; alt++)
1091 : {
1092 953937765 : if (!TEST_BIT (preferred_alternatives, alt))
1093 832239407 : continue;
1094 :
1095 121698358 : auto *op_alt = &recog_op_alt[alt * recog_data.n_operands];
1096 121698358 : auto cl = alternative_class (op_alt, opno);
1097 : /* The two extremes are easy:
1098 :
1099 : - We should record the filter if CL matches the
1100 : allocno class.
1101 :
1102 : - We should ignore the filter if CL and the allocno class
1103 : are disjoint. We'll either pick a different alternative
1104 : or reload the operand.
1105 :
1106 : Things are trickier if the classes overlap. However:
1107 :
1108 : - If the allocno class includes registers that are not
1109 : in CL, some choices of hard register will need a reload
1110 : anyway. It isn't obvious that reloads due to filters
1111 : are worse than reloads due to regnos being outside CL.
1112 :
1113 : - Conversely, if the allocno class is a subset of CL,
1114 : any allocation will satisfy the class requirement.
1115 : We should try to make sure it satisfies the filter
1116 : requirement too. This is useful if, for example,
1117 : an allocno needs to be in "low" registers to satisfy
1118 : some uses, and its allocno class is therefore those
1119 : low registers, but the allocno is elsewhere allowed
1120 : to be in any even-numbered register. Picking an
1121 : even-numbered low register satisfies both types of use. */
1122 121698358 : if (!ira_class_subset_p[ALLOCNO_CLASS (a)][cl])
1123 28410911 : continue;
1124 :
1125 93287447 : auto filters = alternative_register_filters (op_alt, opno);
1126 93287447 : if (!filters)
1127 93287447 : continue;
1128 :
1129 0 : filters |= ALLOCNO_REGISTER_FILTERS (a);
1130 0 : ALLOCNO_SET_REGISTER_FILTERS (a, filters);
1131 : }
1132 : }
1133 : }
1134 83175472 : }
1135 :
1136 : /* Look through the CALL_INSN_FUNCTION_USAGE of a call insn INSN, and see if
1137 : we find a SET rtx that we can use to deduce that a register can be cheaply
1138 : caller-saved. Return such a register, or NULL_RTX if none is found. */
1139 : static rtx
1140 5946193 : find_call_crossed_cheap_reg (rtx_insn *insn)
1141 : {
1142 5946193 : rtx cheap_reg = NULL_RTX;
1143 5946193 : rtx exp = CALL_INSN_FUNCTION_USAGE (insn);
1144 :
1145 18195802 : while (exp != NULL)
1146 : {
1147 12397968 : rtx x = XEXP (exp, 0);
1148 12397968 : if (GET_CODE (x) == SET)
1149 : {
1150 : exp = x;
1151 : break;
1152 : }
1153 12249609 : exp = XEXP (exp, 1);
1154 : }
1155 5946193 : if (exp != NULL)
1156 : {
1157 148359 : basic_block bb = BLOCK_FOR_INSN (insn);
1158 148359 : rtx reg = SET_SRC (exp);
1159 148359 : rtx_insn *prev = PREV_INSN (insn);
1160 296733 : while (prev && !(INSN_P (prev)
1161 148359 : && BLOCK_FOR_INSN (prev) != bb))
1162 : {
1163 148374 : if (NONDEBUG_INSN_P (prev))
1164 : {
1165 148359 : rtx set = single_set (prev);
1166 :
1167 148359 : if (set && rtx_equal_p (SET_DEST (set), reg))
1168 : {
1169 148359 : rtx src = SET_SRC (set);
1170 116575 : if (!REG_P (src) || HARD_REGISTER_P (src)
1171 264528 : || !pseudo_regno_single_word_and_live_p (REGNO (src)))
1172 : break;
1173 29542 : if (!modified_between_p (src, prev, insn))
1174 5946193 : cheap_reg = src;
1175 : break;
1176 : }
1177 0 : if (set && rtx_equal_p (SET_SRC (set), reg))
1178 : {
1179 0 : rtx dest = SET_DEST (set);
1180 0 : if (!REG_P (dest) || HARD_REGISTER_P (dest)
1181 0 : || !pseudo_regno_single_word_and_live_p (REGNO (dest)))
1182 : break;
1183 0 : if (!modified_between_p (dest, prev, insn))
1184 5946193 : cheap_reg = dest;
1185 : break;
1186 : }
1187 :
1188 0 : if (reg_set_p (reg, prev))
1189 : break;
1190 : }
1191 15 : prev = PREV_INSN (prev);
1192 : }
1193 : }
1194 5946193 : return cheap_reg;
1195 : }
1196 :
1197 : /* Determine whether INSN is a register to register copy of the type where
1198 : we do not need to make the source and destiniation registers conflict.
1199 : If this is a copy instruction, then return the source reg. Otherwise,
1200 : return NULL_RTX. */
1201 : rtx
1202 303591889 : non_conflicting_reg_copy_p (rtx_insn *insn)
1203 : {
1204 : /* Reload has issues with overlapping pseudos being assigned to the
1205 : same hard register, so don't allow it. See PR87600 for details. */
1206 303591889 : if (!targetm.lra_p ())
1207 : return NULL_RTX;
1208 :
1209 303591889 : rtx set = single_set (insn);
1210 :
1211 : /* Disallow anything other than a simple register to register copy
1212 : that has no side effects. */
1213 303591889 : if (set == NULL_RTX
1214 288688586 : || !REG_P (SET_DEST (set))
1215 212044066 : || !REG_P (SET_SRC (set))
1216 374870873 : || side_effects_p (set))
1217 232312905 : return NULL_RTX;
1218 :
1219 71278984 : int dst_regno = REGNO (SET_DEST (set));
1220 71278984 : int src_regno = REGNO (SET_SRC (set));
1221 71278984 : machine_mode mode = GET_MODE (SET_DEST (set));
1222 :
1223 : /* By definition, a register does not conflict with itself, therefore we
1224 : do not have to handle it specially. Returning NULL_RTX now, helps
1225 : simplify the callers of this function. */
1226 71278984 : if (dst_regno == src_regno)
1227 : return NULL_RTX;
1228 :
1229 : /* Computing conflicts for register pairs is difficult to get right, so
1230 : for now, disallow it. */
1231 71278984 : if ((HARD_REGISTER_NUM_P (dst_regno)
1232 19382093 : && hard_regno_nregs (dst_regno, mode) != 1)
1233 90499107 : || (HARD_REGISTER_NUM_P (src_regno)
1234 10435951 : && hard_regno_nregs (src_regno, mode) != 1))
1235 : return NULL_RTX;
1236 :
1237 : return SET_SRC (set);
1238 : }
1239 :
1240 : #ifdef EH_RETURN_DATA_REGNO
1241 :
1242 : /* Add EH return hard registers as conflict hard registers to allocnos
1243 : living at end of BB. For most allocnos it is already done in
1244 : process_bb_node_lives when we processing input edges but it does
1245 : not work when and EH edge is edge out of the current region. This
1246 : function covers such out of region edges. */
1247 : static void
1248 14404085 : process_out_of_region_eh_regs (basic_block bb)
1249 : {
1250 14404085 : edge e;
1251 14404085 : edge_iterator ei;
1252 14404085 : unsigned int i;
1253 14404085 : bitmap_iterator bi;
1254 14404085 : bool eh_p = false;
1255 :
1256 35014757 : FOR_EACH_EDGE (e, ei, bb->succs)
1257 20610672 : if ((e->flags & EDGE_EH)
1258 20610672 : && IRA_BB_NODE (e->dest)->parent != IRA_BB_NODE (bb)->parent)
1259 : eh_p = true;
1260 :
1261 14404085 : if (! eh_p)
1262 14395800 : return;
1263 :
1264 110736 : EXECUTE_IF_SET_IN_BITMAP (df_get_live_out (bb), FIRST_PSEUDO_REGISTER, i, bi)
1265 : {
1266 102451 : ira_allocno_t a = ira_curr_regno_allocno_map[i];
1267 207095 : for (int n = ALLOCNO_NUM_OBJECTS (a) - 1; n >= 0; n--)
1268 : {
1269 104644 : ira_object_t obj = ALLOCNO_OBJECT (a, n);
1270 418576 : OBJECT_CONFLICT_HARD_REGS (obj) |= eh_return_data_regs;
1271 104644 : OBJECT_TOTAL_CONFLICT_HARD_REGS (obj) |= eh_return_data_regs;
1272 : }
1273 : }
1274 : }
1275 :
1276 : #endif
1277 :
1278 : /* Add conflicts for object OBJ from REGION landing pads using CALLEE_ABI. */
1279 : static void
1280 3486263 : add_conflict_from_region_landing_pads (eh_region region, ira_object_t obj,
1281 : function_abi callee_abi)
1282 : {
1283 3486263 : ira_allocno_t a = OBJECT_ALLOCNO (obj);
1284 3486263 : rtx_code_label *landing_label;
1285 3486263 : basic_block landing_bb;
1286 :
1287 7122388 : for (eh_landing_pad lp = region->landing_pads; lp ; lp = lp->next_lp)
1288 : {
1289 6043810 : if ((landing_label = lp->landing_pad) != NULL
1290 6043810 : && (landing_bb = BLOCK_FOR_INSN (landing_label)) != NULL
1291 12087571 : && (region->type != ERT_CLEANUP
1292 4551467 : || bitmap_bit_p (df_get_live_in (landing_bb),
1293 : ALLOCNO_REGNO (a))))
1294 : {
1295 2407685 : HARD_REG_SET new_conflict_regs
1296 2407685 : = callee_abi.mode_clobbers (ALLOCNO_MODE (a));
1297 9630740 : OBJECT_CONFLICT_HARD_REGS (obj) |= new_conflict_regs;
1298 2407685 : OBJECT_TOTAL_CONFLICT_HARD_REGS (obj) |= new_conflict_regs;
1299 2407685 : return;
1300 : }
1301 : }
1302 : }
1303 :
1304 : /* Process insns of the basic block given by its LOOP_TREE_NODE to
1305 : update allocno live ranges, allocno hard register conflicts,
1306 : intersected calls, and register pressure info for allocnos for the
1307 : basic block for and regions containing the basic block. */
1308 : static void
1309 16493595 : process_bb_node_lives (ira_loop_tree_node_t loop_tree_node)
1310 : {
1311 16493595 : int i, freq;
1312 16493595 : unsigned int j;
1313 16493595 : basic_block bb;
1314 16493595 : rtx_insn *insn;
1315 16493595 : bitmap_iterator bi;
1316 16493595 : bitmap reg_live_out;
1317 16493595 : unsigned int px;
1318 16493595 : bool set_p;
1319 :
1320 16493595 : bb = loop_tree_node->bb;
1321 16493595 : if (bb != NULL)
1322 : {
1323 70854554 : for (i = 0; i < ira_pressure_classes_num; i++)
1324 : {
1325 56450469 : curr_reg_pressure[ira_pressure_classes[i]] = 0;
1326 56450469 : high_pressure_start_point[ira_pressure_classes[i]] = -1;
1327 : }
1328 14404085 : curr_bb_node = loop_tree_node;
1329 14404085 : reg_live_out = df_get_live_out (bb);
1330 14404085 : sparseset_clear (objects_live);
1331 28808170 : REG_SET_TO_HARD_REG_SET (hard_regs_live, reg_live_out);
1332 14404085 : hard_regs_live &= ~(eliminable_regset | ira_no_alloc_regs);
1333 1339579905 : for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1334 1325175820 : if (TEST_HARD_REG_BIT (hard_regs_live, i))
1335 : {
1336 1108381 : enum reg_class aclass, pclass, cl;
1337 :
1338 1108381 : aclass = ira_allocno_class_translate[REGNO_REG_CLASS (i)];
1339 1108381 : pclass = ira_pressure_class_translate[aclass];
1340 10511759 : for (j = 0;
1341 10511759 : (cl = ira_reg_class_super_classes[pclass][j])
1342 10511759 : != LIM_REG_CLASSES;
1343 : j++)
1344 : {
1345 9403378 : if (! ira_reg_pressure_class_p[cl])
1346 8294997 : continue;
1347 1108381 : curr_reg_pressure[cl]++;
1348 1108381 : if (curr_bb_node->reg_pressure[cl] < curr_reg_pressure[cl])
1349 1108381 : curr_bb_node->reg_pressure[cl] = curr_reg_pressure[cl];
1350 1108381 : ira_assert (curr_reg_pressure[cl]
1351 : <= ira_class_hard_regs_num[cl]);
1352 : }
1353 : }
1354 154734454 : EXECUTE_IF_SET_IN_BITMAP (reg_live_out, FIRST_PSEUDO_REGISTER, j, bi)
1355 140330369 : mark_pseudo_regno_live (j);
1356 :
1357 : #ifdef EH_RETURN_DATA_REGNO
1358 14404085 : process_out_of_region_eh_regs (bb);
1359 : #endif
1360 :
1361 14404085 : freq = REG_FREQ_FROM_BB (bb);
1362 8629121 : if (freq == 0)
1363 2008136 : freq = 1;
1364 :
1365 : /* Invalidate all allocno_saved_at_call entries. */
1366 14404085 : last_call_num++;
1367 :
1368 : /* Scan the code of this basic block, noting which allocnos and
1369 : hard regs are born or die.
1370 :
1371 : Note that this loop treats uninitialized values as live until
1372 : the beginning of the block. For example, if an instruction
1373 : uses (reg:DI foo), and only (subreg:SI (reg:DI foo) 0) is ever
1374 : set, FOO will remain live until the beginning of the block.
1375 : Likewise if FOO is not set at all. This is unnecessarily
1376 : pessimistic, but it probably doesn't matter much in practice. */
1377 173062515 : FOR_BB_INSNS_REVERSE (bb, insn)
1378 : {
1379 158658430 : ira_allocno_t a;
1380 158658430 : df_ref def, use;
1381 158658430 : bool call_p;
1382 :
1383 158658430 : if (!NONDEBUG_INSN_P (insn))
1384 75482958 : continue;
1385 :
1386 83175472 : if (internal_flag_ira_verbose > 2 && ira_dump_file != NULL)
1387 1479 : fprintf (ira_dump_file, " Insn %u(l%d): point = %d\n",
1388 1479 : INSN_UID (insn), loop_tree_node->parent->loop_num,
1389 : curr_point);
1390 :
1391 83175472 : call_p = CALL_P (insn);
1392 83175472 : ignore_reg_for_conflicts = non_conflicting_reg_copy_p (insn);
1393 :
1394 : /* Mark each defined value as live. We need to do this for
1395 : unused values because they still conflict with quantities
1396 : that are live at the time of the definition.
1397 :
1398 : Ignore DF_REF_MAY_CLOBBERs on a call instruction. Such
1399 : references represent the effect of the called function
1400 : on a call-clobbered register. Marking the register as
1401 : live would stop us from allocating it to a call-crossing
1402 : allocno. */
1403 637623594 : FOR_EACH_INSN_DEF (def, insn)
1404 554448122 : if (!call_p || !DF_REF_FLAGS_IS_SET (def, DF_REF_MAY_CLOBBER))
1405 70475626 : mark_ref_live (def);
1406 :
1407 : /* If INSN has multiple outputs, then any value used in one
1408 : of the outputs conflicts with the other outputs. Model this
1409 : by making the used value live during the output phase.
1410 :
1411 : It is unsafe to use !single_set here since it will ignore
1412 : an unused output. Just because an output is unused does
1413 : not mean the compiler can assume the side effect will not
1414 : occur. Consider if ALLOCNO appears in the address of an
1415 : output and we reload the output. If we allocate ALLOCNO
1416 : to the same hard register as an unused output we could
1417 : set the hard register before the output reload insn. */
1418 83175472 : if (GET_CODE (PATTERN (insn)) == PARALLEL && multiple_sets (insn))
1419 1757186 : FOR_EACH_INSN_USE (use, insn)
1420 : {
1421 1380237 : int i;
1422 1380237 : rtx reg;
1423 :
1424 1380237 : reg = DF_REF_REG (use);
1425 4341146 : for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1426 : {
1427 3327990 : rtx set;
1428 :
1429 3327990 : set = XVECEXP (PATTERN (insn), 0, i);
1430 3327990 : if (GET_CODE (set) == SET
1431 3327990 : && reg_overlap_mentioned_p (reg, SET_DEST (set)))
1432 : {
1433 : /* After the previous loop, this is a no-op if
1434 : REG is contained within SET_DEST (SET). */
1435 367081 : mark_ref_live (use);
1436 367081 : break;
1437 : }
1438 : }
1439 : }
1440 :
1441 83175472 : preferred_alternatives = ira_setup_alts (insn);
1442 83175472 : process_register_constraint_filters ();
1443 83175472 : process_single_reg_class_operands (false, freq);
1444 :
1445 83175472 : if (call_p)
1446 : {
1447 : /* Try to find a SET in the CALL_INSN_FUNCTION_USAGE, and from
1448 : there, try to find a pseudo that is live across the call but
1449 : can be cheaply reconstructed from the return value. */
1450 5946193 : rtx cheap_reg = find_call_crossed_cheap_reg (insn);
1451 5946193 : if (cheap_reg != NULL_RTX)
1452 29542 : add_reg_note (insn, REG_RETURNED, cheap_reg);
1453 :
1454 5946193 : last_call_num++;
1455 5946193 : sparseset_clear (allocnos_processed);
1456 : /* The current set of live allocnos are live across the call. */
1457 468457564 : EXECUTE_IF_SET_IN_SPARSESET (objects_live, i)
1458 : {
1459 228282589 : ira_object_t obj = ira_object_id_map[i];
1460 228282589 : a = OBJECT_ALLOCNO (obj);
1461 228282589 : int num = ALLOCNO_NUM (a);
1462 228282589 : function_abi callee_abi = insn_callee_abi (insn);
1463 :
1464 : /* Don't allocate allocnos that cross setjmps or any
1465 : call, if this function receives a nonlocal
1466 : goto. */
1467 228282589 : if (cfun->has_nonlocal_label
1468 228282589 : || (!targetm.setjmp_preserves_nonvolatile_regs_p ()
1469 228280020 : && (find_reg_note (insn, REG_SETJMP, NULL_RTX)
1470 : != NULL_RTX)))
1471 : {
1472 10788 : SET_HARD_REG_SET (OBJECT_CONFLICT_HARD_REGS (obj));
1473 228282589 : SET_HARD_REG_SET (OBJECT_TOTAL_CONFLICT_HARD_REGS (obj));
1474 : }
1475 228282589 : eh_region r;
1476 228282589 : if (can_throw_internal (insn)
1477 228282589 : && (r = get_eh_region_from_rtx (insn)) != NULL)
1478 3486263 : add_conflict_from_region_landing_pads (r, obj, callee_abi);
1479 228282589 : if (sparseset_bit_p (allocnos_processed, num))
1480 103961353 : continue;
1481 124321236 : sparseset_set_bit (allocnos_processed, num);
1482 :
1483 124321236 : if (allocno_saved_at_call[num] != last_call_num)
1484 : /* Here we are mimicking caller-save.cc behavior
1485 : which does not save hard register at a call if
1486 : it was saved on previous call in the same basic
1487 : block and the hard register was not mentioned
1488 : between the two calls. */
1489 39636286 : ALLOCNO_CALL_FREQ (a) += freq;
1490 : /* Mark it as saved at the next call. */
1491 124321236 : allocno_saved_at_call[num] = last_call_num + 1;
1492 124321236 : ALLOCNO_CALLS_CROSSED_NUM (a)++;
1493 124321236 : ALLOCNO_CROSSED_CALLS_ABIS (a) |= 1 << callee_abi.id ();
1494 124321236 : ALLOCNO_CROSSED_CALLS_CLOBBERED_REGS (a)
1495 124321236 : |= callee_abi.full_and_partial_reg_clobbers ();
1496 124321236 : if (cheap_reg != NULL_RTX
1497 124321236 : && ALLOCNO_REGNO (a) == (int) REGNO (cheap_reg))
1498 29542 : ALLOCNO_CHEAP_CALLS_CROSSED_NUM (a)++;
1499 : }
1500 : }
1501 :
1502 : /* See which defined values die here. Note that we include
1503 : the call insn in the lifetimes of these values, so we don't
1504 : mistakenly consider, for e.g. an addressing mode with a
1505 : side-effect like a post-increment fetching the address,
1506 : that the use happens before the call, and the def to happen
1507 : after the call: we believe both to happen before the actual
1508 : call. (We don't handle return-values here.) */
1509 637623594 : FOR_EACH_INSN_DEF (def, insn)
1510 554448122 : if (!call_p || !DF_REF_FLAGS_IS_SET (def, DF_REF_MAY_CLOBBER))
1511 70475626 : mark_ref_dead (def);
1512 :
1513 83175472 : make_early_clobber_and_input_conflicts ();
1514 :
1515 83175472 : curr_point++;
1516 :
1517 : /* Mark each used value as live. */
1518 183426073 : FOR_EACH_INSN_USE (use, insn)
1519 100250601 : mark_ref_live (use);
1520 :
1521 83175472 : process_single_reg_class_operands (true, freq);
1522 :
1523 83175472 : set_p = mark_hard_reg_early_clobbers (insn, true);
1524 :
1525 83175472 : if (set_p)
1526 : {
1527 10589953 : mark_hard_reg_early_clobbers (insn, false);
1528 :
1529 : /* Mark each hard reg as live again. For example, a
1530 : hard register can be in clobber and in an insn
1531 : input. */
1532 26173415 : FOR_EACH_INSN_USE (use, insn)
1533 : {
1534 15583462 : rtx ureg = DF_REF_REG (use);
1535 :
1536 15583462 : if (GET_CODE (ureg) == SUBREG)
1537 306944 : ureg = SUBREG_REG (ureg);
1538 15583462 : if (! REG_P (ureg) || REGNO (ureg) >= FIRST_PSEUDO_REGISTER)
1539 9673074 : continue;
1540 :
1541 5910388 : mark_ref_live (use);
1542 : }
1543 : }
1544 :
1545 83175472 : curr_point++;
1546 : }
1547 14404085 : ignore_reg_for_conflicts = NULL_RTX;
1548 :
1549 14404085 : if (bb_has_eh_pred (bb))
1550 211028 : for (j = 0; ; ++j)
1551 : {
1552 633084 : unsigned int regno = EH_RETURN_DATA_REGNO (j);
1553 422056 : if (regno == INVALID_REGNUM)
1554 : break;
1555 422056 : make_hard_regno_live (regno);
1556 422056 : }
1557 :
1558 : /* Allocnos can't go in stack regs at the start of a basic block
1559 : that is reached by an abnormal edge. Likewise for registers
1560 : that are at least partly call clobbered, because caller-save,
1561 : fixup_abnormal_edges and possibly the table driven EH machinery
1562 : are not quite ready to handle such allocnos live across such
1563 : edges. */
1564 14404085 : if (bb_has_abnormal_pred (bb))
1565 : {
1566 : #ifdef STACK_REGS
1567 676085 : EXECUTE_IF_SET_IN_SPARSESET (objects_live, px)
1568 : {
1569 462644 : ira_allocno_t a = OBJECT_ALLOCNO (ira_object_id_map[px]);
1570 :
1571 462644 : ALLOCNO_NO_STACK_REG_P (a) = true;
1572 462644 : ALLOCNO_TOTAL_NO_STACK_REG_P (a) = true;
1573 : }
1574 1920969 : for (px = FIRST_STACK_REG; px <= LAST_STACK_REG; px++)
1575 1707528 : make_hard_regno_live (px);
1576 : #endif
1577 : /* No need to record conflicts for call clobbered regs if we
1578 : have nonlocal labels around, as we don't ever try to
1579 : allocate such regs in this case. */
1580 213441 : if (!cfun->has_nonlocal_label
1581 213441 : && has_abnormal_call_or_eh_pred_edge_p (bb))
1582 19624767 : for (px = 0; px < FIRST_PSEUDO_REGISTER; px++)
1583 19413748 : if (eh_edge_abi.clobbers_at_least_part_of_reg_p (px)
1584 : #ifdef REAL_PIC_OFFSET_TABLE_REGNUM
1585 : /* We should create a conflict of PIC pseudo with
1586 : PIC hard reg as PIC hard reg can have a wrong
1587 : value after jump described by the abnormal edge.
1588 : In this case we cannot allocate PIC hard reg to
1589 : PIC pseudo as PIC pseudo will also have a wrong
1590 : value. This code is not critical as LRA can fix
1591 : it but it is better to have the right allocation
1592 : earlier. */
1593 19552488 : || (px == REAL_PIC_OFFSET_TABLE_REGNUM
1594 211019 : && pic_offset_table_rtx != NULL_RTX
1595 6218 : && REGNO (pic_offset_table_rtx) >= FIRST_PSEUDO_REGISTER)
1596 : #endif
1597 : )
1598 17560435 : make_hard_regno_live (px);
1599 : }
1600 :
1601 219086277 : EXECUTE_IF_SET_IN_SPARSESET (objects_live, i)
1602 204682192 : make_object_dead (ira_object_id_map[i]);
1603 :
1604 14404085 : curr_point++;
1605 :
1606 : }
1607 : /* Propagate register pressure to upper loop tree nodes. */
1608 16493595 : if (loop_tree_node != ira_loop_tree_root)
1609 73953616 : for (i = 0; i < ira_pressure_classes_num; i++)
1610 : {
1611 58931383 : enum reg_class pclass;
1612 :
1613 58931383 : pclass = ira_pressure_classes[i];
1614 58931383 : if (loop_tree_node->reg_pressure[pclass]
1615 58931383 : > loop_tree_node->parent->reg_pressure[pclass])
1616 4216998 : loop_tree_node->parent->reg_pressure[pclass]
1617 4216998 : = loop_tree_node->reg_pressure[pclass];
1618 : }
1619 16493595 : }
1620 :
1621 : /* Create and set up IRA_START_POINT_RANGES and
1622 : IRA_FINISH_POINT_RANGES. */
1623 : static void
1624 3103524 : create_start_finish_chains (void)
1625 : {
1626 3103524 : ira_object_t obj;
1627 3103524 : ira_object_iterator oi;
1628 3103524 : live_range_t r;
1629 :
1630 3103524 : ira_start_point_ranges
1631 3103524 : = (live_range_t *) ira_allocate (ira_max_point * sizeof (live_range_t));
1632 3103524 : memset (ira_start_point_ranges, 0, ira_max_point * sizeof (live_range_t));
1633 3103524 : ira_finish_point_ranges
1634 3103524 : = (live_range_t *) ira_allocate (ira_max_point * sizeof (live_range_t));
1635 3103524 : memset (ira_finish_point_ranges, 0, ira_max_point * sizeof (live_range_t));
1636 80346793 : FOR_EACH_OBJECT (obj, oi)
1637 183041858 : for (r = OBJECT_LIVE_RANGES (obj); r != NULL; r = r->next)
1638 : {
1639 105798589 : r->start_next = ira_start_point_ranges[r->start];
1640 105798589 : ira_start_point_ranges[r->start] = r;
1641 105798589 : r->finish_next = ira_finish_point_ranges[r->finish];
1642 105798589 : ira_finish_point_ranges[r->finish] = r;
1643 : }
1644 3103524 : }
1645 :
1646 : /* Rebuild IRA_START_POINT_RANGES and IRA_FINISH_POINT_RANGES after
1647 : new live ranges and program points were added as a result if new
1648 : insn generation. */
1649 : void
1650 1632162 : ira_rebuild_start_finish_chains (void)
1651 : {
1652 1632162 : ira_free (ira_finish_point_ranges);
1653 1632162 : ira_free (ira_start_point_ranges);
1654 1632162 : create_start_finish_chains ();
1655 1632162 : }
1656 :
1657 : /* Compress allocno live ranges by removing program points where
1658 : nothing happens. */
1659 : static void
1660 1471362 : remove_some_program_points_and_update_live_ranges (void)
1661 : {
1662 1471362 : unsigned i;
1663 1471362 : int n;
1664 1471362 : int *map;
1665 1471362 : ira_object_t obj;
1666 1471362 : ira_object_iterator oi;
1667 1471362 : live_range_t r, prev_r, next_r;
1668 1471362 : sbitmap_iterator sbi;
1669 1471362 : bool born_p, dead_p, prev_born_p, prev_dead_p;
1670 :
1671 1471362 : auto_sbitmap born (ira_max_point);
1672 1471362 : auto_sbitmap dead (ira_max_point);
1673 1471362 : bitmap_clear (born);
1674 1471362 : bitmap_clear (dead);
1675 35486446 : FOR_EACH_OBJECT (obj, oi)
1676 87315140 : for (r = OBJECT_LIVE_RANGES (obj); r != NULL; r = r->next)
1677 : {
1678 53300056 : ira_assert (r->start <= r->finish);
1679 53300056 : bitmap_set_bit (born, r->start);
1680 53300056 : bitmap_set_bit (dead, r->finish);
1681 : }
1682 :
1683 1471362 : auto_sbitmap born_or_dead (ira_max_point);
1684 1471362 : bitmap_ior (born_or_dead, born, dead);
1685 1471362 : map = (int *) ira_allocate (sizeof (int) * ira_max_point);
1686 1471362 : n = -1;
1687 1471362 : prev_born_p = prev_dead_p = false;
1688 66536466 : EXECUTE_IF_SET_IN_BITMAP (born_or_dead, 0, i, sbi)
1689 : {
1690 63593742 : born_p = bitmap_bit_p (born, i);
1691 63593742 : dead_p = bitmap_bit_p (dead, i);
1692 63593742 : if ((prev_born_p && ! prev_dead_p && born_p && ! dead_p)
1693 57504073 : || (prev_dead_p && ! prev_born_p && dead_p && ! born_p))
1694 16066859 : map[i] = n;
1695 : else
1696 47526883 : map[i] = ++n;
1697 63593742 : prev_born_p = born_p;
1698 63593742 : prev_dead_p = dead_p;
1699 : }
1700 :
1701 1471362 : n++;
1702 1471362 : if (internal_flag_ira_verbose > 1 && ira_dump_file != NULL)
1703 95 : fprintf (ira_dump_file, "Compressing live ranges: from %d to %d - %d%%\n",
1704 95 : ira_max_point, n, 100 * n / ira_max_point);
1705 1471362 : ira_max_point = n;
1706 :
1707 35486446 : FOR_EACH_OBJECT (obj, oi)
1708 87315140 : for (r = OBJECT_LIVE_RANGES (obj), prev_r = NULL; r != NULL; r = next_r)
1709 : {
1710 53300056 : next_r = r->next;
1711 53300056 : r->start = map[r->start];
1712 53300056 : r->finish = map[r->finish];
1713 53300056 : if (prev_r == NULL || prev_r->start > r->finish + 1)
1714 : {
1715 40741662 : prev_r = r;
1716 40741662 : continue;
1717 : }
1718 12558394 : prev_r->start = r->start;
1719 12558394 : prev_r->next = next_r;
1720 12558394 : ira_finish_live_range (r);
1721 : }
1722 :
1723 1471362 : ira_free (map);
1724 1471362 : }
1725 :
1726 : /* Print live ranges R to file F. */
1727 : void
1728 1466 : ira_print_live_range_list (FILE *f, live_range_t r)
1729 : {
1730 3234 : for (; r != NULL; r = r->next)
1731 1768 : fprintf (f, " [%d..%d]", r->start, r->finish);
1732 1466 : fprintf (f, "\n");
1733 1466 : }
1734 :
1735 : DEBUG_FUNCTION void
1736 0 : debug (live_range &ref)
1737 : {
1738 0 : ira_print_live_range_list (stderr, &ref);
1739 0 : }
1740 :
1741 : DEBUG_FUNCTION void
1742 0 : debug (live_range *ptr)
1743 : {
1744 0 : if (ptr)
1745 0 : debug (*ptr);
1746 : else
1747 0 : fprintf (stderr, "<nil>\n");
1748 0 : }
1749 :
1750 : /* Print live ranges R to stderr. */
1751 : void
1752 0 : ira_debug_live_range_list (live_range_t r)
1753 : {
1754 0 : ira_print_live_range_list (stderr, r);
1755 0 : }
1756 :
1757 : /* Print live ranges of object OBJ to file F. */
1758 : static void
1759 1328 : print_object_live_ranges (FILE *f, ira_object_t obj)
1760 : {
1761 0 : ira_print_live_range_list (f, OBJECT_LIVE_RANGES (obj));
1762 0 : }
1763 :
1764 : /* Print live ranges of allocno A to file F. */
1765 : static void
1766 1328 : print_allocno_live_ranges (FILE *f, ira_allocno_t a)
1767 : {
1768 1328 : int n = ALLOCNO_NUM_OBJECTS (a);
1769 1328 : int i;
1770 :
1771 2656 : for (i = 0; i < n; i++)
1772 : {
1773 1328 : fprintf (f, " a%d(r%d", ALLOCNO_NUM (a), ALLOCNO_REGNO (a));
1774 1328 : if (n > 1)
1775 0 : fprintf (f, " [%d]", i);
1776 1328 : fprintf (f, "):");
1777 1328 : print_object_live_ranges (f, ALLOCNO_OBJECT (a, i));
1778 : }
1779 1328 : }
1780 :
1781 : /* Print live ranges of allocno A to stderr. */
1782 : void
1783 0 : ira_debug_allocno_live_ranges (ira_allocno_t a)
1784 : {
1785 0 : print_allocno_live_ranges (stderr, a);
1786 0 : }
1787 :
1788 : /* Print live ranges of all allocnos to file F. */
1789 : static void
1790 190 : print_live_ranges (FILE *f)
1791 : {
1792 190 : ira_allocno_t a;
1793 190 : ira_allocno_iterator ai;
1794 :
1795 1518 : FOR_EACH_ALLOCNO (a, ai)
1796 1328 : print_allocno_live_ranges (f, a);
1797 190 : }
1798 :
1799 : /* Print live ranges of all allocnos to stderr. */
1800 : void
1801 0 : ira_debug_live_ranges (void)
1802 : {
1803 0 : print_live_ranges (stderr);
1804 0 : }
1805 :
1806 : /* The main entry function creates live ranges, set up
1807 : CONFLICT_HARD_REGS and TOTAL_CONFLICT_HARD_REGS for objects, and
1808 : calculate register pressure info. */
1809 : void
1810 1471362 : ira_create_allocno_live_ranges (void)
1811 : {
1812 1471362 : objects_live = sparseset_alloc (ira_objects_num);
1813 1471362 : allocnos_processed = sparseset_alloc (ira_allocnos_num);
1814 1471362 : curr_point = 0;
1815 1471362 : last_call_num = 0;
1816 1471362 : allocno_saved_at_call
1817 1471362 : = (int *) ira_allocate (ira_allocnos_num * sizeof (int));
1818 1471362 : memset (allocno_saved_at_call, 0, ira_allocnos_num * sizeof (int));
1819 1471362 : ira_traverse_loop_tree (true, ira_loop_tree_root, NULL,
1820 : process_bb_node_lives);
1821 1471362 : ira_max_point = curr_point;
1822 1471362 : create_start_finish_chains ();
1823 1471362 : if (internal_flag_ira_verbose > 2 && ira_dump_file != NULL)
1824 95 : print_live_ranges (ira_dump_file);
1825 : /* Clean up. */
1826 1471362 : ira_free (allocno_saved_at_call);
1827 1471362 : sparseset_free (objects_live);
1828 1471362 : sparseset_free (allocnos_processed);
1829 1471362 : }
1830 :
1831 : /* Compress allocno live ranges. */
1832 : void
1833 1471362 : ira_compress_allocno_live_ranges (void)
1834 : {
1835 1471362 : remove_some_program_points_and_update_live_ranges ();
1836 1471362 : ira_rebuild_start_finish_chains ();
1837 1471362 : if (internal_flag_ira_verbose > 2 && ira_dump_file != NULL)
1838 : {
1839 95 : fprintf (ira_dump_file, "Ranges after the compression:\n");
1840 95 : print_live_ranges (ira_dump_file);
1841 : }
1842 1471362 : }
1843 :
1844 : /* Free arrays IRA_START_POINT_RANGES and IRA_FINISH_POINT_RANGES. */
1845 : void
1846 1471362 : ira_finish_allocno_live_ranges (void)
1847 : {
1848 1471362 : ira_free (ira_finish_point_ranges);
1849 1471362 : ira_free (ira_start_point_ranges);
1850 1471362 : }
|