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 38627790 : make_hard_regno_live (int regno)
98 : {
99 38627790 : 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 15394301 : make_hard_regno_dead (int regno)
106 : {
107 15394301 : unsigned int i;
108 281457413 : EXECUTE_IF_SET_IN_SPARSESET (objects_live, i)
109 : {
110 266063112 : ira_object_t obj = ira_object_id_map[i];
111 :
112 267782831 : if (ignore_reg_for_conflicts != NULL_RTX
113 174506722 : && REGNO (ignore_reg_for_conflicts)
114 174506722 : == (unsigned int) ALLOCNO_REGNO (OBJECT_ALLOCNO (obj)))
115 1719719 : continue;
116 :
117 264343393 : SET_HARD_REG_BIT (OBJECT_CONFLICT_HARD_REGS (obj), regno);
118 264343393 : SET_HARD_REG_BIT (OBJECT_TOTAL_CONFLICT_HARD_REGS (obj), regno);
119 : }
120 15394301 : CLEAR_HARD_REG_BIT (hard_regs_live, regno);
121 15394301 : }
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 244811067 : make_object_live (ira_object_t obj)
127 : {
128 244811067 : sparseset_set_bit (objects_live, OBJECT_CONFLICT_ID (obj));
129 :
130 244811067 : live_range_t lr = OBJECT_LIVE_RANGES (obj);
131 244811067 : if (lr == NULL
132 206850240 : || (lr->finish != curr_point && lr->finish + 1 != curr_point))
133 56028026 : ira_add_live_range_to_object (obj, curr_point, -1);
134 244811067 : }
135 :
136 : /* Update ALLOCNO_EXCESS_PRESSURE_POINTS_NUM for the allocno
137 : associated with object OBJ. */
138 : static void
139 252487396 : update_allocno_pressure_excess_length (ira_object_t obj)
140 : {
141 252487396 : ira_allocno_t a = OBJECT_ALLOCNO (obj);
142 252487396 : int start, i;
143 252487396 : enum reg_class aclass, pclass, cl;
144 252487396 : live_range_t p;
145 :
146 252487396 : aclass = ALLOCNO_CLASS (a);
147 252487396 : pclass = ira_pressure_class_translate[aclass];
148 2479466468 : for (i = 0;
149 2479466468 : (cl = ira_reg_class_super_classes[pclass][i]) != LIM_REG_CLASSES;
150 : i++)
151 : {
152 2226979072 : if (! ira_reg_pressure_class_p[cl])
153 1979462071 : continue;
154 247517001 : if (high_pressure_start_point[cl] < 0)
155 76539887 : continue;
156 170977114 : p = OBJECT_LIVE_RANGES (obj);
157 170977114 : ira_assert (p != NULL);
158 170977114 : start = (high_pressure_start_point[cl] > p->start
159 170977114 : ? high_pressure_start_point[cl] : p->start);
160 170977114 : ALLOCNO_EXCESS_PRESSURE_POINTS_NUM (a) += curr_point - start + 1;
161 : }
162 252487396 : }
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 244811067 : make_object_dead (ira_object_t obj)
168 : {
169 244811067 : live_range_t lr;
170 244811067 : int regno;
171 244811067 : int ignore_regno = -1;
172 244811067 : int ignore_total_regno = -1;
173 244811067 : int end_regno = -1;
174 :
175 244811067 : 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 244811067 : if (ignore_reg_for_conflicts != NULL_RTX
180 244811067 : && REGNO (ignore_reg_for_conflicts) < FIRST_PSEUDO_REGISTER)
181 : {
182 3508929 : end_regno = END_REGNO (ignore_reg_for_conflicts);
183 3508929 : ignore_regno = ignore_total_regno = REGNO (ignore_reg_for_conflicts);
184 :
185 7017858 : for (regno = ignore_regno; regno < end_regno; regno++)
186 : {
187 3508929 : if (TEST_HARD_REG_BIT (OBJECT_CONFLICT_HARD_REGS (obj), regno))
188 523461 : ignore_regno = end_regno;
189 3508929 : if (TEST_HARD_REG_BIT (OBJECT_TOTAL_CONFLICT_HARD_REGS (obj), regno))
190 523461 : ignore_total_regno = end_regno;
191 : }
192 : }
193 :
194 979244268 : OBJECT_CONFLICT_HARD_REGS (obj) |= hard_regs_live;
195 247796535 : 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 247796535 : for (regno = ignore_regno; regno < end_regno; regno++)
200 2985468 : CLEAR_HARD_REG_BIT (OBJECT_CONFLICT_HARD_REGS (obj), regno);
201 247796535 : for (regno = ignore_total_regno; regno < end_regno; regno++)
202 2985468 : CLEAR_HARD_REG_BIT (OBJECT_TOTAL_CONFLICT_HARD_REGS (obj), regno);
203 :
204 244811067 : lr = OBJECT_LIVE_RANGES (obj);
205 244811067 : ira_assert (lr != NULL);
206 244811067 : lr->finish = curr_point;
207 244811067 : update_allocno_pressure_excess_length (obj);
208 244811067 : }
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 261820720 : inc_register_pressure (enum reg_class pclass, int n)
220 : {
221 261820720 : int i;
222 261820720 : enum reg_class cl;
223 :
224 2570044116 : for (i = 0;
225 2570044116 : (cl = ira_reg_class_super_classes[pclass][i]) != LIM_REG_CLASSES;
226 : i++)
227 : {
228 2308223396 : if (! ira_reg_pressure_class_p[cl])
229 2051120860 : continue;
230 257102536 : curr_reg_pressure[cl] += n;
231 257102536 : if (high_pressure_start_point[cl] < 0
232 107944775 : && (curr_reg_pressure[cl] > ira_class_hard_regs_num[cl]))
233 1768613 : high_pressure_start_point[cl] = curr_point;
234 257102536 : if (curr_bb_node->reg_pressure[cl] < curr_reg_pressure[cl])
235 221385349 : curr_bb_node->reg_pressure[cl] = curr_reg_pressure[cl];
236 : }
237 261820720 : }
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 53987633 : dec_register_pressure (enum reg_class pclass, int nregs)
246 : {
247 53987633 : int i;
248 53987633 : unsigned int j;
249 53987633 : enum reg_class cl;
250 53987633 : bool set_p = false;
251 :
252 53987633 : for (i = 0;
253 524123505 : (cl = ira_reg_class_super_classes[pclass][i]) != LIM_REG_CLASSES;
254 : i++)
255 : {
256 470135872 : if (! ira_reg_pressure_class_p[cl])
257 416653454 : continue;
258 53482418 : curr_reg_pressure[cl] -= nregs;
259 53482418 : ira_assert (curr_reg_pressure[cl] >= 0);
260 53482418 : if (high_pressure_start_point[cl] >= 0
261 4778790 : && curr_reg_pressure[cl] <= ira_class_hard_regs_num[cl])
262 470135872 : set_p = true;
263 : }
264 53987633 : if (set_p)
265 : {
266 8174217 : EXECUTE_IF_SET_IN_SPARSESET (objects_live, j)
267 7676329 : update_allocno_pressure_excess_length (ira_object_id_map[j]);
268 4728923 : for (i = 0;
269 5226811 : (cl = ira_reg_class_super_classes[pclass][i]) != LIM_REG_CLASSES;
270 : i++)
271 : {
272 4728923 : if (! ira_reg_pressure_class_p[cl])
273 4231035 : continue;
274 497888 : if (high_pressure_start_point[cl] >= 0
275 497888 : && curr_reg_pressure[cl] <= ira_class_hard_regs_num[cl])
276 497888 : high_pressure_start_point[cl] = -1;
277 : }
278 : }
279 53987633 : }
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 122877 : pseudo_regno_single_word_and_live_p (int regno)
285 : {
286 122877 : ira_allocno_t a = ira_curr_regno_allocno_map[regno];
287 122877 : ira_object_t obj;
288 :
289 122877 : if (a == NULL)
290 : return false;
291 122877 : if (ALLOCNO_NUM_OBJECTS (a) > 1)
292 : return false;
293 :
294 122877 : obj = ALLOCNO_OBJECT (a, 0);
295 :
296 122877 : 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 230940869 : mark_pseudo_regno_live (int regno)
303 : {
304 230940869 : ira_allocno_t a = ira_curr_regno_allocno_map[regno];
305 230940869 : enum reg_class pclass;
306 230940869 : int i, n, nregs;
307 :
308 230940869 : if (a == NULL)
309 : return;
310 :
311 : /* Invalidate because it is referenced. */
312 230940869 : allocno_saved_at_call[ALLOCNO_NUM (a)] = 0;
313 :
314 230940869 : n = ALLOCNO_NUM_OBJECTS (a);
315 230940869 : pclass = ira_pressure_class_translate[ALLOCNO_CLASS (a)];
316 230940869 : nregs = ira_reg_class_max_nregs[ALLOCNO_CLASS (a)][ALLOCNO_MODE (a)];
317 230940869 : if (n > 1)
318 : {
319 : /* We track every subobject separately. */
320 69986097 : gcc_assert (nregs == n);
321 : nregs = 1;
322 : }
323 :
324 531867835 : for (i = 0; i < n; i++)
325 : {
326 300926966 : ira_object_t obj = ALLOCNO_OBJECT (a, i);
327 :
328 300926966 : if (sparseset_bit_p (objects_live, OBJECT_CONFLICT_ID (obj)))
329 56449945 : continue;
330 :
331 244477021 : inc_register_pressure (pclass, nregs);
332 244477021 : 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 884517 : mark_pseudo_regno_subword_live (int regno, int subword)
341 : {
342 884517 : ira_allocno_t a = ira_curr_regno_allocno_map[regno];
343 884517 : int n;
344 884517 : enum reg_class pclass;
345 884517 : ira_object_t obj;
346 :
347 884517 : if (a == NULL)
348 : return;
349 :
350 : /* Invalidate because it is referenced. */
351 884517 : allocno_saved_at_call[ALLOCNO_NUM (a)] = 0;
352 :
353 884517 : n = ALLOCNO_NUM_OBJECTS (a);
354 884517 : if (n == 1)
355 : {
356 40259 : mark_pseudo_regno_live (regno);
357 40259 : return;
358 : }
359 :
360 844258 : pclass = ira_pressure_class_translate[ALLOCNO_CLASS (a)];
361 844258 : gcc_assert
362 : (n == ira_reg_class_max_nregs[ALLOCNO_CLASS (a)][ALLOCNO_MODE (a)]);
363 844258 : obj = ALLOCNO_OBJECT (a, subword);
364 :
365 844258 : if (sparseset_bit_p (objects_live, OBJECT_CONFLICT_ID (obj)))
366 : return;
367 :
368 334046 : inc_register_pressure (pclass, 1);
369 334046 : 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 105493631 : mark_hard_reg_live (rtx reg)
377 : {
378 105493631 : int regno = REGNO (reg);
379 :
380 105493631 : if (! TEST_HARD_REG_BIT (ira_no_alloc_regs, regno))
381 : {
382 32135718 : int last = END_REGNO (reg);
383 32135718 : enum reg_class aclass, pclass;
384 :
385 64271436 : while (regno < last)
386 : {
387 32135718 : if (! TEST_HARD_REG_BIT (hard_regs_live, regno)
388 32135718 : && ! TEST_HARD_REG_BIT (eliminable_regset, regno))
389 : {
390 17009653 : aclass = ira_hard_regno_allocno_class[regno];
391 17009653 : pclass = ira_pressure_class_translate[aclass];
392 17009653 : inc_register_pressure (pclass, 1);
393 17009653 : make_hard_regno_live (regno);
394 : }
395 32135718 : regno++;
396 : }
397 : }
398 105493631 : }
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 89991639 : mark_pseudo_reg_live (rtx orig_reg, unsigned regno)
405 : {
406 89991639 : if (read_modify_subreg_p (orig_reg))
407 : {
408 1320704 : mark_pseudo_regno_subword_live (regno,
409 884517 : subreg_lowpart_p (orig_reg) ? 0 : 1);
410 : }
411 : else
412 89107122 : mark_pseudo_regno_live (regno);
413 89991639 : }
414 :
415 : /* Mark the register referenced by use or def REF as live. */
416 : static void
417 193587450 : mark_ref_live (df_ref ref)
418 : {
419 193587450 : rtx reg = DF_REF_REG (ref);
420 193587450 : rtx orig_reg = reg;
421 :
422 193587450 : if (GET_CODE (reg) == SUBREG)
423 3121748 : reg = SUBREG_REG (reg);
424 :
425 193587450 : if (REGNO (reg) >= FIRST_PSEUDO_REGISTER)
426 88093819 : mark_pseudo_reg_live (orig_reg, REGNO (reg));
427 : else
428 105493631 : mark_hard_reg_live (reg);
429 193587450 : }
430 :
431 : /* Mark the pseudo register REGNO as dead. Update all information about
432 : live ranges and register pressure. */
433 : static void
434 36930750 : mark_pseudo_regno_dead (int regno)
435 : {
436 36930750 : ira_allocno_t a = ira_curr_regno_allocno_map[regno];
437 36930750 : int n, i, nregs;
438 36930750 : enum reg_class cl;
439 :
440 36930750 : if (a == NULL)
441 : return;
442 :
443 : /* Invalidate because it is referenced. */
444 36930750 : allocno_saved_at_call[ALLOCNO_NUM (a)] = 0;
445 :
446 36930750 : n = ALLOCNO_NUM_OBJECTS (a);
447 36930750 : cl = ira_pressure_class_translate[ALLOCNO_CLASS (a)];
448 36930750 : nregs = ira_reg_class_max_nregs[ALLOCNO_CLASS (a)][ALLOCNO_MODE (a)];
449 36930750 : if (n > 1)
450 : {
451 : /* We track every subobject separately. */
452 1322856 : gcc_assert (nregs == n);
453 : nregs = 1;
454 : }
455 75184356 : for (i = 0; i < n; i++)
456 : {
457 38253606 : ira_object_t obj = ALLOCNO_OBJECT (a, i);
458 38253606 : if (!sparseset_bit_p (objects_live, OBJECT_CONFLICT_ID (obj)))
459 3717 : continue;
460 :
461 38249889 : dec_register_pressure (cl, nregs);
462 38249889 : 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 347862 : mark_pseudo_regno_subword_dead (int regno, int subword)
470 : {
471 347862 : ira_allocno_t a = ira_curr_regno_allocno_map[regno];
472 347862 : int n;
473 347862 : enum reg_class cl;
474 347862 : ira_object_t obj;
475 :
476 347862 : if (a == NULL)
477 : return;
478 :
479 : /* Invalidate because it is referenced. */
480 347862 : allocno_saved_at_call[ALLOCNO_NUM (a)] = 0;
481 :
482 347862 : n = ALLOCNO_NUM_OBJECTS (a);
483 347862 : if (n == 1)
484 : /* The allocno as a whole doesn't die in this case. */
485 : return;
486 :
487 343443 : cl = ira_pressure_class_translate[ALLOCNO_CLASS (a)];
488 343443 : gcc_assert
489 : (n == ira_reg_class_max_nregs[ALLOCNO_CLASS (a)][ALLOCNO_MODE (a)]);
490 :
491 343443 : obj = ALLOCNO_OBJECT (a, subword);
492 343443 : if (!sparseset_bit_p (objects_live, OBJECT_CONFLICT_ID (obj)))
493 : return;
494 :
495 343443 : dec_register_pressure (cl, 1);
496 343443 : 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 48093767 : mark_hard_reg_dead (rtx reg)
503 : {
504 48093767 : int regno = REGNO (reg);
505 :
506 48093767 : if (! TEST_HARD_REG_BIT (ira_no_alloc_regs, regno))
507 : {
508 15396355 : int last = END_REGNO (reg);
509 15396355 : enum reg_class aclass, pclass;
510 :
511 30792710 : while (regno < last)
512 : {
513 15396355 : if (TEST_HARD_REG_BIT (hard_regs_live, regno))
514 : {
515 15394301 : aclass = ira_hard_regno_allocno_class[regno];
516 15394301 : pclass = ira_pressure_class_translate[aclass];
517 15394301 : dec_register_pressure (pclass, 1);
518 15394301 : make_hard_regno_dead (regno);
519 : }
520 15396355 : regno++;
521 : }
522 : }
523 48093767 : }
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 37278612 : mark_pseudo_reg_dead (rtx orig_reg, unsigned regno)
530 : {
531 37278612 : if (read_modify_subreg_p (orig_reg))
532 : {
533 523344 : mark_pseudo_regno_subword_dead (regno,
534 347862 : subreg_lowpart_p (orig_reg) ? 0 : 1);
535 : }
536 : else
537 36930750 : mark_pseudo_regno_dead (regno);
538 37278612 : }
539 :
540 : /* Mark the register referenced by definition DEF as dead, if the
541 : definition is a total one. */
542 : static void
543 83478883 : mark_ref_dead (df_ref def)
544 : {
545 83478883 : rtx reg = DF_REF_REG (def);
546 83478883 : rtx orig_reg = reg;
547 :
548 83478883 : if (DF_REF_FLAGS_IS_SET (def, DF_REF_CONDITIONAL))
549 : return;
550 :
551 83478883 : if (GET_CODE (reg) == SUBREG)
552 929270 : reg = SUBREG_REG (reg);
553 :
554 83478883 : if (DF_REF_FLAGS_IS_SET (def, DF_REF_PARTIAL)
555 83478883 : && (GET_CODE (orig_reg) != SUBREG
556 336381 : || REGNO (reg) < FIRST_PSEUDO_REGISTER
557 336381 : || !read_modify_subreg_p (orig_reg)))
558 : return;
559 :
560 83474559 : if (REGNO (reg) >= FIRST_PSEUDO_REGISTER)
561 35380792 : mark_pseudo_reg_dead (orig_reg, REGNO (reg));
562 : else
563 48093767 : 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 3003675 : make_pseudo_conflict (rtx reg, enum reg_class cl, rtx dreg, rtx orig_dreg,
574 : bool advance_p)
575 : {
576 3003675 : rtx orig_reg = reg;
577 3003675 : ira_allocno_t a;
578 :
579 3003675 : if (GET_CODE (reg) == SUBREG)
580 86799 : reg = SUBREG_REG (reg);
581 :
582 3003675 : if (! REG_P (reg) || REGNO (reg) < FIRST_PSEUDO_REGISTER)
583 : return advance_p;
584 :
585 1023840 : a = ira_curr_regno_allocno_map[REGNO (reg)];
586 1023840 : if (! reg_classes_intersect_p (cl, ALLOCNO_CLASS (a)))
587 : return advance_p;
588 :
589 948910 : if (advance_p)
590 903935 : curr_point++;
591 :
592 948910 : mark_pseudo_reg_live (orig_reg, REGNO (reg));
593 948910 : mark_pseudo_reg_live (orig_dreg, REGNO (dreg));
594 948910 : mark_pseudo_reg_dead (orig_reg, REGNO (reg));
595 948910 : mark_pseudo_reg_dead (orig_dreg, REGNO (dreg));
596 :
597 948910 : 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 3053425 : 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 3053425 : if (! reg_classes_intersect_p (def_cl, use_cl))
612 : return advance_p;
613 :
614 2988112 : 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 2988112 : if (use < recog_data.n_operands - 1
624 1197317 : && recog_data.constraints[use][0] == '%')
625 6473 : advance_p
626 6473 : = make_pseudo_conflict (recog_data.operand[use + 1],
627 : use_cl, dreg, orig_dreg, advance_p);
628 2988112 : if (use >= 1
629 2987804 : && recog_data.constraints[use - 1][0] == '%')
630 9090 : advance_p
631 9090 : = 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 14895066 : check_and_make_def_conflict (int alt, int def, enum reg_class def_cl,
659 : bool for_tie_p)
660 : {
661 14895066 : int use, use_match;
662 14895066 : ira_allocno_t a;
663 14895066 : enum reg_class use_cl, acl;
664 14895066 : bool advance_p;
665 14895066 : rtx dreg = recog_data.operand[def];
666 14895066 : rtx orig_dreg = dreg;
667 :
668 14895066 : if (def_cl == NO_REGS)
669 : return;
670 :
671 14895066 : if (GET_CODE (dreg) == SUBREG)
672 112635 : dreg = SUBREG_REG (dreg);
673 :
674 14895066 : if (! REG_P (dreg) || REGNO (dreg) < FIRST_PSEUDO_REGISTER)
675 : return;
676 :
677 12661778 : a = ira_curr_regno_allocno_map[REGNO (dreg)];
678 12661778 : acl = ALLOCNO_CLASS (a);
679 12661778 : if (! reg_classes_intersect_p (acl, def_cl))
680 : return;
681 :
682 12468391 : advance_p = true;
683 :
684 12468391 : int n_operands = recog_data.n_operands;
685 12468391 : const operand_alternative *op_alt = &recog_op_alt[alt * n_operands];
686 51657385 : for (use = 0; use < n_operands; use++)
687 : {
688 39188994 : int alt1;
689 :
690 39188994 : if (use == def || recog_data.operand_type[use] == OP_OUT)
691 12637268 : 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 38933699 : if (op_alt[use].matches == def
701 26551726 : || (for_tie_p
702 13895108 : && rtx_equal_p (recog_data.operand[use],
703 13895108 : recog_data.operand[op_alt[def].matched])))
704 12381973 : continue;
705 :
706 14169753 : if (op_alt[use].anything_ok)
707 : use_cl = ALL_REGS;
708 : else
709 12389081 : use_cl = op_alt[use].cl;
710 12389081 : if (use_cl == NO_REGS)
711 4855773 : 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 9313980 : if (for_tie_p && targetm.class_likely_spilled_p (use_cl))
718 1041634 : 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 21871001 : for (alt1 = 0; alt1 < recog_data.n_alternatives; alt1++)
728 : {
729 18817577 : if (!TEST_BIT (preferred_alternatives, alt1))
730 8948052 : continue;
731 9869525 : const operand_alternative *op_alt1
732 9869525 : = &recog_op_alt[alt1 * n_operands];
733 9869525 : if (op_alt1[use].matches == def
734 7835422 : || (use < n_operands - 1
735 3011232 : && recog_data.constraints[use][0] == '%'
736 8129 : && op_alt1[use + 1].matches == def)
737 7835422 : || (use >= 1
738 7833892 : && recog_data.constraints[use - 1][0] == '%'
739 3188031 : && op_alt1[use - 1].matches == def))
740 : break;
741 4658137 : if (for_tie_p
742 4432395 : && !op_alt1[def].earlyclobber
743 4431231 : && op_alt1[def].matched < 0
744 29923 : && alternative_class (op_alt1, def) != NO_REGS
745 4688060 : && alternative_class (op_alt1, use) != NO_REGS)
746 : break;
747 : }
748 :
749 8272346 : if (alt1 < recog_data.n_alternatives)
750 5218922 : continue;
751 :
752 3053424 : advance_p = check_and_make_def_use_conflict (dreg, orig_dreg, def_cl,
753 : use, use_cl, advance_p);
754 :
755 3053424 : 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 86285201 : make_early_clobber_and_input_conflicts (void)
779 : {
780 86285201 : int alt;
781 86285201 : int def, def_match;
782 86285201 : enum reg_class def_cl;
783 :
784 86285201 : int n_alternatives = recog_data.n_alternatives;
785 86285201 : int n_operands = recog_data.n_operands;
786 86285201 : const operand_alternative *op_alt = recog_op_alt;
787 1194753474 : for (alt = 0; alt < n_alternatives; alt++, op_alt += n_operands)
788 1108468273 : if (TEST_BIT (preferred_alternatives, alt))
789 398096103 : for (def = 0; def < n_operands; def++)
790 : {
791 274862344 : if (op_alt[def].anything_ok)
792 : def_cl = ALL_REGS;
793 : else
794 260294958 : def_cl = op_alt[def].cl;
795 260294958 : if (def_cl != NO_REGS)
796 : {
797 217671590 : if (op_alt[def].earlyclobber)
798 152348 : check_and_make_def_conflict (alt, def, def_cl, false);
799 217519242 : else if (op_alt[def].matched >= 0
800 217519242 : && !targetm.class_likely_spilled_p (def_cl))
801 14703122 : check_and_make_def_conflict (alt, def, def_cl, true);
802 : }
803 :
804 274862344 : if ((def_match = op_alt[def].matches) >= 0
805 274862344 : && (op_alt[def_match].earlyclobber
806 15423657 : || op_alt[def].earlyclobber))
807 : {
808 39596 : if (op_alt[def_match].anything_ok)
809 : def_cl = ALL_REGS;
810 : else
811 39596 : def_cl = op_alt[def_match].cl;
812 39596 : check_and_make_def_conflict (alt, def, def_cl, false);
813 : }
814 : }
815 86285201 : }
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 97211198 : mark_hard_reg_early_clobbers (rtx_insn *insn, bool live_p)
821 : {
822 97211198 : df_ref def;
823 97211198 : bool set_p = false;
824 :
825 709724314 : FOR_EACH_INSN_DEF (def, insn)
826 612513116 : if (DF_REF_FLAGS_IS_SET (def, DF_REF_MUST_CLOBBER))
827 : {
828 22276780 : rtx dreg = DF_REF_REG (def);
829 :
830 22276780 : if (GET_CODE (dreg) == SUBREG)
831 0 : dreg = SUBREG_REG (dreg);
832 22276780 : if (! REG_P (dreg) || REGNO (dreg) >= FIRST_PSEUDO_REGISTER)
833 131672 : 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 22145108 : if (live_p)
839 11072554 : mark_ref_live (def);
840 : else
841 11072554 : mark_ref_dead (def);
842 : set_p = true;
843 : }
844 :
845 97211198 : 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 182861454 : single_reg_class_regno (const char *constraints, rtx op, rtx equiv_const)
852 : {
853 182861454 : int c;
854 182861454 : int regno, next_regno;
855 182861454 : enum reg_class next_cl;
856 182861454 : enum constraint_num cn;
857 :
858 182861454 : regno = -1;
859 182861454 : alternative_mask preferred = preferred_alternatives;
860 955545000 : while ((c = *constraints))
861 : {
862 941067734 : if (c == '#')
863 0 : preferred &= ~ALTERNATIVE_BIT (0);
864 941067734 : else if (c == ',')
865 257550865 : preferred >>= 1;
866 683516869 : else if (preferred & 1)
867 206052673 : switch (c)
868 : {
869 : case 'g':
870 : return -1;
871 :
872 138 : case '{':
873 138 : next_regno = decode_hard_reg_constraint (constraints);
874 138 : if (regno >= 0 && regno != next_regno)
875 : return -1;
876 : regno = next_regno;
877 : break;
878 :
879 185474221 : default:
880 : /* ??? Is this the best way to handle memory constraints? */
881 185474221 : cn = lookup_constraint (constraints);
882 185474221 : if (insn_extra_memory_constraint (cn)
883 173057134 : || insn_extra_special_memory_constraint (cn)
884 : || insn_extra_relaxed_memory_constraint (cn)
885 358531353 : || insn_extra_address_constraint (cn))
886 : return -1;
887 172461721 : if (constraint_satisfied_p (op, cn)
888 172461721 : || (equiv_const != NULL_RTX
889 0 : && CONSTANT_P (equiv_const)
890 0 : && constraint_satisfied_p (equiv_const, cn)))
891 : return -1;
892 157496161 : next_cl = reg_class_for_constraint (cn);
893 125190257 : if (next_cl == NO_REGS)
894 : break;
895 121921630 : next_regno = ira_class_singleton[next_cl][GET_MODE (op)];
896 121921630 : if (regno < 0
897 121921630 : ? next_regno < 0
898 : : regno != next_regno)
899 : return -1;
900 : regno = next_regno;
901 : break;
902 :
903 13258906 : case '0': case '1': case '2': case '3': case '4':
904 13258906 : case '5': case '6': case '7': case '8': case '9':
905 13258906 : {
906 13258906 : char *end;
907 13258906 : unsigned long dup = strtoul (constraints, &end, 10);
908 13258906 : constraints = end;
909 13258906 : next_regno
910 26517812 : = single_reg_class_regno (recog_data.constraints[dup],
911 13258906 : recog_data.operand[dup], NULL_RTX);
912 13258906 : if (regno < 0
913 13258906 : ? next_regno < 0
914 : : regno != next_regno)
915 13015306 : return -1;
916 243600 : regno = next_regno;
917 243600 : continue;
918 243600 : }
919 : }
920 772439946 : 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 185051914 : single_reg_operand_class_regno (int op_num)
930 : {
931 185051914 : if (op_num < 0 || recog_data.n_alternatives == 0)
932 : return -1;
933 169602548 : return single_reg_class_regno (recog_data.constraints[op_num],
934 169602548 : 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 28594 : ira_implicitly_set_insn_hard_regs (HARD_REG_SET *set,
942 : alternative_mask preferred)
943 : {
944 28594 : int i, c, regno = 0;
945 28594 : enum reg_class cl;
946 28594 : rtx op;
947 28594 : machine_mode mode;
948 :
949 28594 : CLEAR_HARD_REG_SET (*set);
950 88025 : for (i = 0; i < recog_data.n_operands; i++)
951 : {
952 59431 : op = recog_data.operand[i];
953 :
954 59431 : if (GET_CODE (op) == SUBREG)
955 1075 : op = SUBREG_REG (op);
956 :
957 59431 : if (GET_CODE (op) == SCRATCH
958 59431 : || (REG_P (op) && (regno = REGNO (op)) >= FIRST_PSEUDO_REGISTER))
959 : {
960 39153 : const char *p = recog_data.constraints[i];
961 :
962 78306 : mode = (GET_CODE (op) == SCRATCH
963 39153 : ? GET_MODE (op) : PSEUDO_REGNO_MODE (regno));
964 39153 : cl = NO_REGS;
965 39153 : for (alternative_mask curr_preferred = preferred;
966 1487242 : (c = *p);
967 1448089 : p += CONSTRAINT_LEN (c, p))
968 1448089 : if (c == '#')
969 0 : curr_preferred &= ~ALTERNATIVE_BIT (0);
970 1448089 : else if (c == ',')
971 496256 : curr_preferred >>= 1;
972 951833 : else if (curr_preferred & 1)
973 : {
974 598377 : cl = reg_class_for_constraint (lookup_constraint (p));
975 262199 : if (cl != NO_REGS)
976 : {
977 : /* There is no register pressure problem if all of the
978 : regs in this class are fixed. */
979 257399 : int regno = ira_class_singleton[cl][mode];
980 257399 : if (regno >= 0)
981 1612 : add_to_hard_reg_set (set, mode, regno);
982 : }
983 340978 : 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 28594 : }
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 172570402 : process_single_reg_constrained_operands (bool in_p, int freq)
999 : {
1000 172570402 : int i, regno, hard_regno;
1001 172570402 : unsigned int px;
1002 172570402 : enum reg_class cl;
1003 172570402 : rtx operand;
1004 172570402 : ira_allocno_t operand_a, a;
1005 :
1006 542510964 : for (i = 0; i < recog_data.n_operands; i++)
1007 : {
1008 369940562 : operand = recog_data.operand[i];
1009 369940562 : if (in_p && recog_data.operand_type[i] != OP_IN
1010 63128020 : && recog_data.operand_type[i] != OP_INOUT)
1011 369126087 : continue;
1012 184970281 : if (! in_p && recog_data.operand_type[i] != OP_OUT
1013 121923894 : && recog_data.operand_type[i] != OP_INOUT)
1014 121842261 : continue;
1015 185051914 : hard_regno = single_reg_operand_class_regno (i);
1016 185051914 : if (hard_regno < 0)
1017 184237439 : continue;
1018 :
1019 814475 : operand_a = NULL;
1020 :
1021 814475 : if (GET_CODE (operand) == SUBREG)
1022 61692 : operand = SUBREG_REG (operand);
1023 :
1024 814475 : if (REG_P (operand)
1025 814475 : && (regno = REGNO (operand)) >= FIRST_PSEUDO_REGISTER)
1026 : {
1027 797265 : enum reg_class aclass;
1028 :
1029 797265 : cl = NO_REGS;
1030 797265 : int nregs = hard_regno_nregs (hard_regno, recog_data.operand_mode[i]);
1031 1630018 : for (int j = 0; j < nregs; ++j)
1032 832753 : cl = reg_class_superunion[cl][REGNO_REG_CLASS (hard_regno + j)];
1033 :
1034 797265 : operand_a = ira_curr_regno_allocno_map[regno];
1035 797265 : aclass = ALLOCNO_CLASS (operand_a);
1036 797265 : 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 788917 : machine_mode ymode, xmode;
1046 788917 : int xregno, yregno;
1047 788917 : poly_int64 offset;
1048 :
1049 788917 : xmode = recog_data.operand_mode[i];
1050 788917 : xregno = hard_regno;
1051 788917 : gcc_assert (xregno >= 0);
1052 788917 : ymode = ALLOCNO_MODE (operand_a);
1053 788917 : offset = subreg_lowpart_offset (ymode, xmode);
1054 788917 : yregno = simplify_subreg_regno (xregno, xmode, offset, ymode);
1055 788917 : if (yregno >= 0
1056 788917 : && ira_class_hard_reg_index[aclass][yregno] >= 0)
1057 : {
1058 788917 : int cost;
1059 :
1060 788917 : ira_allocate_and_set_costs
1061 788917 : (&ALLOCNO_CONFLICT_HARD_REG_COSTS (operand_a),
1062 : aclass, 0);
1063 788917 : ira_init_register_move_cost_if_necessary (xmode);
1064 1577834 : cost = freq * (in_p
1065 788917 : ? ira_register_move_cost[xmode][aclass][cl]
1066 453545 : : ira_register_move_cost[xmode][cl][aclass]);
1067 788917 : ALLOCNO_CONFLICT_HARD_REG_COSTS (operand_a)
1068 788917 : [ira_class_hard_reg_index[aclass][yregno]] -= cost;
1069 : }
1070 : }
1071 : }
1072 :
1073 814475 : HARD_REG_SET hard_regs;
1074 814475 : CLEAR_HARD_REG_SET (hard_regs);
1075 814475 : add_to_hard_reg_set (&hard_regs, recog_data.operand_mode[i], hard_regno);
1076 :
1077 31724923 : EXECUTE_IF_SET_IN_SPARSESET (objects_live, px)
1078 : {
1079 30910448 : ira_object_t obj = ira_object_id_map[px];
1080 30910448 : a = OBJECT_ALLOCNO (obj);
1081 30910448 : 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 90217104 : OBJECT_CONFLICT_HARD_REGS (obj) |= hard_regs;
1087 30910448 : OBJECT_TOTAL_CONFLICT_HARD_REGS (obj) |= hard_regs;
1088 : }
1089 : }
1090 : }
1091 172570402 : }
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 86285201 : process_register_constraint_filters ()
1098 : {
1099 271255482 : for (int opno = 0; opno < recog_data.n_operands; ++opno)
1100 : {
1101 184970281 : rtx op = recog_data.operand[opno];
1102 184970281 : if (SUBREG_P (op))
1103 3078430 : op = SUBREG_REG (op);
1104 184970281 : if (REG_P (op) && !HARD_REGISTER_P (op))
1105 : {
1106 76654213 : ira_allocno_t a = ira_curr_regno_allocno_map[REGNO (op)];
1107 1096148116 : for (int alt = 0; alt < recog_data.n_alternatives; alt++)
1108 : {
1109 1019493903 : if (!TEST_BIT (preferred_alternatives, alt))
1110 892534560 : continue;
1111 :
1112 126959343 : auto *op_alt = &recog_op_alt[alt * recog_data.n_operands];
1113 126959343 : 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 126959343 : if (!ira_class_subset_p[ALLOCNO_CLASS (a)][cl])
1140 29629159 : continue;
1141 :
1142 97330184 : auto filters = alternative_register_filters (op_alt, opno);
1143 97330184 : if (!filters)
1144 97330184 : continue;
1145 :
1146 0 : filters |= ALLOCNO_REGISTER_FILTERS (a);
1147 0 : ALLOCNO_SET_REGISTER_FILTERS (a, filters);
1148 : }
1149 : }
1150 : }
1151 86285201 : }
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 6203978 : find_call_crossed_cheap_reg (rtx_call_insn *insn)
1250 : {
1251 6203978 : rtx cheap_reg = NULL_RTX;
1252 6203978 : rtx exp = CALL_INSN_FUNCTION_USAGE (insn);
1253 :
1254 18205962 : while (exp != NULL)
1255 : {
1256 12158432 : rtx x = XEXP (exp, 0);
1257 12158432 : if (GET_CODE (x) == SET)
1258 : {
1259 : exp = x;
1260 : break;
1261 : }
1262 12001984 : exp = XEXP (exp, 1);
1263 : }
1264 6203978 : if (exp != NULL)
1265 : {
1266 156448 : basic_block bb = BLOCK_FOR_INSN (insn);
1267 156448 : rtx reg = SET_SRC (exp);
1268 156448 : rtx_insn *prev = PREV_INSN (insn);
1269 312915 : while (prev && !(INSN_P (prev)
1270 156448 : && BLOCK_FOR_INSN (prev) != bb))
1271 : {
1272 156467 : if (NONDEBUG_INSN_P (prev))
1273 : {
1274 156448 : rtx set = single_set (prev);
1275 :
1276 156448 : if (set && rtx_equal_p (SET_DEST (set), reg))
1277 : {
1278 156448 : rtx src = SET_SRC (set);
1279 123299 : if (!REG_P (src) || HARD_REGISTER_P (src)
1280 279325 : || !pseudo_regno_single_word_and_live_p (REGNO (src)))
1281 : break;
1282 34342 : if (!modified_between_p (src, prev, insn))
1283 6203978 : 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 6203978 : 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 6203978 : 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 316054206 : 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 316054206 : if (!targetm.lra_p ())
1316 : return NULL_RTX;
1317 :
1318 316054206 : rtx set = single_set (insn);
1319 :
1320 : /* Disallow anything other than a simple register to register copy
1321 : that has no side effects. */
1322 316054206 : if (set == NULL_RTX
1323 300533069 : || !REG_P (SET_DEST (set))
1324 221603280 : || !REG_P (SET_SRC (set))
1325 390857045 : || side_effects_p (set))
1326 : return NULL_RTX;
1327 :
1328 74802839 : int dst_regno = REGNO (SET_DEST (set));
1329 74802839 : int src_regno = REGNO (SET_SRC (set));
1330 74802839 : 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 74802839 : 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 74802839 : if ((HARD_REGISTER_NUM_P (dst_regno)
1341 20483848 : && hard_regno_nregs (dst_regno, mode) != 1)
1342 95120609 : || (HARD_REGISTER_NUM_P (src_regno)
1343 10736500 : && hard_regno_nregs (src_regno, mode) != 1))
1344 312812 : 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 14825658 : process_out_of_region_eh_regs (basic_block bb)
1358 : {
1359 14825658 : edge e;
1360 14825658 : edge_iterator ei;
1361 14825658 : unsigned int i;
1362 14825658 : bitmap_iterator bi;
1363 14825658 : bool eh_p = false;
1364 :
1365 35999150 : FOR_EACH_EDGE (e, ei, bb->succs)
1366 21173492 : if ((e->flags & EDGE_EH)
1367 21173492 : && IRA_BB_NODE (e->dest)->parent != IRA_BB_NODE (bb)->parent)
1368 21173492 : eh_p = true;
1369 :
1370 14825658 : if (! eh_p)
1371 14817774 : return;
1372 :
1373 106632 : EXECUTE_IF_SET_IN_BITMAP (df_get_live_out (bb), FIRST_PSEUDO_REGISTER, i, bi)
1374 : {
1375 98748 : ira_allocno_t a = ira_curr_regno_allocno_map[i];
1376 203598 : for (int n = ALLOCNO_NUM_OBJECTS (a) - 1; n >= 0; n--)
1377 : {
1378 104850 : ira_object_t obj = ALLOCNO_OBJECT (a, n);
1379 419400 : OBJECT_CONFLICT_HARD_REGS (obj) |= eh_return_data_regs;
1380 104850 : 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 3678745 : add_conflict_from_region_landing_pads (eh_region region, ira_object_t obj,
1390 : function_abi callee_abi)
1391 : {
1392 3678745 : ira_allocno_t a = OBJECT_ALLOCNO (obj);
1393 3678745 : rtx_code_label *landing_label;
1394 3678745 : basic_block landing_bb;
1395 :
1396 6961418 : for (eh_landing_pad lp = region->landing_pads; lp ; lp = lp->next_lp)
1397 : {
1398 5717971 : if ((landing_label = lp->landing_pad) != NULL
1399 5717971 : && (landing_bb = BLOCK_FOR_INSN (landing_label)) != NULL
1400 11435887 : && (region->type != ERT_CLEANUP
1401 4181090 : || bitmap_bit_p (df_get_live_in (landing_bb),
1402 : ALLOCNO_REGNO (a))))
1403 : {
1404 2435298 : HARD_REG_SET new_conflict_regs
1405 2435298 : = callee_abi.mode_clobbers (ALLOCNO_MODE (a));
1406 9741192 : OBJECT_CONFLICT_HARD_REGS (obj) |= new_conflict_regs;
1407 2435298 : OBJECT_TOTAL_CONFLICT_HARD_REGS (obj) |= new_conflict_regs;
1408 2435298 : 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 16988501 : process_bb_node_lives (ira_loop_tree_node_t loop_tree_node)
1419 : {
1420 16988501 : int i, freq;
1421 16988501 : unsigned int j, k;
1422 16988501 : basic_block bb;
1423 16988501 : rtx_insn *insn;
1424 16988501 : bitmap_iterator bi;
1425 16988501 : bitmap reg_live_out;
1426 16988501 : unsigned int px;
1427 16988501 : bool set_p;
1428 :
1429 16988501 : bb = loop_tree_node->bb;
1430 16988501 : if (bb != NULL)
1431 : {
1432 72966042 : for (i = 0; i < ira_pressure_classes_num; i++)
1433 : {
1434 58140384 : curr_reg_pressure[ira_pressure_classes[i]] = 0;
1435 58140384 : high_pressure_start_point[ira_pressure_classes[i]] = -1;
1436 : }
1437 14825658 : curr_bb_node = loop_tree_node;
1438 14825658 : reg_live_out = df_get_live_out (bb);
1439 14825658 : sparseset_clear (objects_live);
1440 29651316 : REG_SET_TO_HARD_REG_SET (hard_regs_live, reg_live_out);
1441 14825658 : hard_regs_live &= ~(eliminable_regset | ira_no_alloc_regs);
1442 14825658 : hard_reg_set_iterator hrsi;
1443 14825658 : k = 0;
1444 15977993 : EXECUTE_IF_SET_IN_HARD_REG_SET (hard_regs_live, 0, k, hrsi)
1445 : {
1446 1152335 : enum reg_class aclass, pclass, cl;
1447 :
1448 1152335 : aclass = ira_allocno_class_translate[REGNO_REG_CLASS (k)];
1449 1152335 : pclass = ira_pressure_class_translate[aclass];
1450 10932271 : for (j = 0;
1451 10932271 : (cl = ira_reg_class_super_classes[pclass][j])
1452 10932271 : != LIM_REG_CLASSES;
1453 : j++)
1454 : {
1455 9779936 : if (! ira_reg_pressure_class_p[cl])
1456 8627601 : continue;
1457 1152335 : curr_reg_pressure[cl]++;
1458 1152335 : if (curr_bb_node->reg_pressure[cl] < curr_reg_pressure[cl])
1459 1152335 : curr_bb_node->reg_pressure[cl] = curr_reg_pressure[cl];
1460 1152335 : ira_assert (curr_reg_pressure[cl]
1461 : <= ira_class_hard_regs_num[cl]);
1462 : }
1463 : }
1464 156619146 : EXECUTE_IF_SET_IN_BITMAP (reg_live_out, FIRST_PSEUDO_REGISTER, j, bi)
1465 141793488 : mark_pseudo_regno_live (j);
1466 :
1467 : #ifdef EH_RETURN_DATA_REGNO
1468 14825658 : process_out_of_region_eh_regs (bb);
1469 : #endif
1470 :
1471 14825658 : freq = REG_FREQ_FROM_BB (bb);
1472 8793422 : if (freq == 0)
1473 2088297 : freq = 1;
1474 :
1475 : /* Invalidate all allocno_saved_at_call entries. */
1476 14825658 : 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 180641661 : FOR_BB_INSNS_REVERSE (bb, insn)
1488 : {
1489 165816003 : ira_allocno_t a;
1490 165816003 : df_ref def, use;
1491 165816003 : bool call_p;
1492 :
1493 165816003 : if (!NONDEBUG_INSN_P (insn))
1494 79530802 : continue;
1495 :
1496 86285201 : if (internal_flag_ira_verbose > 2 && ira_dump_file != NULL)
1497 1897 : fprintf (ira_dump_file, " Insn %u(l%d): point = %d\n",
1498 1897 : INSN_UID (insn), loop_tree_node->parent->loop_num,
1499 : curr_point);
1500 :
1501 86285201 : call_p = CALL_P (insn);
1502 86285201 : 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 676849891 : FOR_EACH_INSN_DEF (def, insn)
1514 590564690 : if (!call_p || !DF_REF_FLAGS_IS_SET (def, DF_REF_MAY_CLOBBER))
1515 72406329 : 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 86285201 : if (GET_CODE (PATTERN (insn)) == PARALLEL && multiple_sets (insn))
1529 1938537 : FOR_EACH_INSN_USE (use, insn)
1530 : {
1531 1527339 : int i;
1532 1527339 : rtx reg;
1533 :
1534 1527339 : reg = DF_REF_REG (use);
1535 4876143 : for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1536 : {
1537 3758117 : rtx set;
1538 :
1539 3758117 : set = XVECEXP (PATTERN (insn), 0, i);
1540 3758117 : if (GET_CODE (set) == SET
1541 3758117 : && 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 409313 : mark_ref_live (use);
1546 409313 : break;
1547 : }
1548 : }
1549 : }
1550 :
1551 86285201 : preferred_alternatives = ira_setup_alts (insn);
1552 86285201 : process_register_constraint_filters ();
1553 86285201 : process_dependent_filters ();
1554 86285201 : process_single_reg_constrained_operands (false, freq);
1555 :
1556 86285201 : 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 6203978 : rtx cheap_reg = find_call_crossed_cheap_reg (call);
1562 6203978 : if (cheap_reg != NULL_RTX)
1563 34342 : add_reg_note (call, REG_RETURNED, cheap_reg);
1564 :
1565 6203978 : last_call_num++;
1566 6203978 : sparseset_clear (allocnos_processed);
1567 6203978 : function_abi callee_abi = insn_callee_abi (call);
1568 : /* Registers of each class needed by the pseudos living
1569 : through this call. */
1570 6203978 : int call_pressure[N_REG_CLASSES];
1571 6203978 : if (ira_flatten_cost_p)
1572 114 : memset (call_pressure, 0, sizeof (call_pressure));
1573 : /* The current set of live allocnos are live across the call. */
1574 464976258 : EXECUTE_IF_SET_IN_SPARSESET (objects_live, i)
1575 : {
1576 229386140 : ira_object_t obj = ira_object_id_map[i];
1577 229386140 : a = OBJECT_ALLOCNO (obj);
1578 229386140 : int num = ALLOCNO_NUM (a);
1579 :
1580 : /* Don't allocate allocnos that cross setjmps or any
1581 : call, if this function receives a nonlocal
1582 : goto. */
1583 229386140 : if (cfun->has_nonlocal_label
1584 229386140 : || (!targetm.setjmp_preserves_nonvolatile_regs_p ()
1585 229383512 : && (find_reg_note (call, REG_SETJMP, NULL_RTX)
1586 : != NULL_RTX)))
1587 : {
1588 15044 : SET_HARD_REG_SET (OBJECT_CONFLICT_HARD_REGS (obj));
1589 229386140 : SET_HARD_REG_SET (OBJECT_TOTAL_CONFLICT_HARD_REGS (obj));
1590 : }
1591 229386140 : eh_region r;
1592 229386140 : if (can_throw_internal (call)
1593 229386140 : && (r = get_eh_region_from_rtx (call)) != NULL)
1594 3678745 : add_conflict_from_region_landing_pads (r, obj, callee_abi);
1595 229386140 : if (sparseset_bit_p (allocnos_processed, num))
1596 104026977 : continue;
1597 125359163 : sparseset_set_bit (allocnos_processed, num);
1598 :
1599 125359163 : if (ira_flatten_cost_p)
1600 : {
1601 515 : enum reg_class cl, aclass = ALLOCNO_CLASS (a);
1602 515 : enum reg_class pclass
1603 515 : = ira_pressure_class_translate[aclass];
1604 515 : int nregs
1605 515 : = ira_reg_class_max_nregs[aclass][ALLOCNO_MODE (a)];
1606 : /* A call that clobbers no register of the class
1607 : does not need a call-preserved register. */
1608 1030 : if (hard_reg_set_intersect_p
1609 1030 : (callee_abi.full_and_partial_reg_clobbers (),
1610 1030 : reg_class_contents[pclass] & ~ira_no_alloc_regs))
1611 3432 : for (int j = 0;
1612 3927 : (cl = ira_reg_class_super_classes[pclass][j])
1613 3927 : != LIM_REG_CLASSES;
1614 : j++)
1615 3432 : call_pressure[cl] += nregs;
1616 : }
1617 :
1618 125359163 : if (allocno_saved_at_call[num] != last_call_num)
1619 : /* Here we are mimicking caller-save.cc behavior
1620 : which does not save hard register at a call if
1621 : it was saved on previous call in the same basic
1622 : block and the hard register was not mentioned
1623 : between the two calls. */
1624 40374365 : ALLOCNO_CALL_FREQ (a) += freq;
1625 : /* Mark it as saved at the next call. */
1626 125359163 : allocno_saved_at_call[num] = last_call_num + 1;
1627 125359163 : ALLOCNO_CALLS_CROSSED_NUM (a)++;
1628 125359163 : ALLOCNO_CROSSED_CALLS_ABIS (a) |= 1 << callee_abi.id ();
1629 125359163 : ALLOCNO_CROSSED_CALLS_CLOBBERED_REGS (a)
1630 125359163 : |= callee_abi.full_and_partial_reg_clobbers ();
1631 125359163 : if (cheap_reg != NULL_RTX
1632 125359163 : && ALLOCNO_REGNO (a) == (int) REGNO (cheap_reg))
1633 34342 : ALLOCNO_CHEAP_CALLS_CROSSED_NUM (a)++;
1634 : }
1635 6203978 : if (ira_flatten_cost_p)
1636 485 : for (int j = 0; j < ira_pressure_classes_num; j++)
1637 : {
1638 371 : enum reg_class cl = ira_pressure_classes[j];
1639 371 : if (curr_bb_node->call_crossing_pressure[cl]
1640 371 : < call_pressure[cl])
1641 40 : curr_bb_node->call_crossing_pressure[cl]
1642 40 : = call_pressure[cl];
1643 : }
1644 : }
1645 :
1646 : /* See which defined values die here. Note that we include
1647 : the call insn in the lifetimes of these values, so we don't
1648 : mistakenly consider, for e.g. an addressing mode with a
1649 : side-effect like a post-increment fetching the address,
1650 : that the use happens before the call, and the def to happen
1651 : after the call: we believe both to happen before the actual
1652 : call. (We don't handle return-values here.) */
1653 676849891 : FOR_EACH_INSN_DEF (def, insn)
1654 590564690 : if (!call_p || !DF_REF_FLAGS_IS_SET (def, DF_REF_MAY_CLOBBER))
1655 72406329 : mark_ref_dead (def);
1656 :
1657 86285201 : make_early_clobber_and_input_conflicts ();
1658 :
1659 86285201 : curr_point++;
1660 :
1661 : /* Mark each used value as live. */
1662 190318943 : FOR_EACH_INSN_USE (use, insn)
1663 104033742 : mark_ref_live (use);
1664 :
1665 86285201 : process_single_reg_constrained_operands (true, freq);
1666 :
1667 86285201 : set_p = mark_hard_reg_early_clobbers (insn, true);
1668 :
1669 86285201 : if (set_p)
1670 : {
1671 10925997 : mark_hard_reg_early_clobbers (insn, false);
1672 :
1673 : /* Mark each hard reg as live again. For example, a
1674 : hard register can be in clobber and in an insn
1675 : input. */
1676 26824096 : FOR_EACH_INSN_USE (use, insn)
1677 : {
1678 15898099 : rtx ureg = DF_REF_REG (use);
1679 :
1680 15898099 : if (GET_CODE (ureg) == SUBREG)
1681 352418 : ureg = SUBREG_REG (ureg);
1682 15898099 : if (! REG_P (ureg) || REGNO (ureg) >= FIRST_PSEUDO_REGISTER)
1683 10232587 : continue;
1684 :
1685 5665512 : mark_ref_live (use);
1686 : }
1687 : }
1688 :
1689 86285201 : curr_point++;
1690 : }
1691 14825658 : ignore_reg_for_conflicts = NULL_RTX;
1692 :
1693 14825658 : if (bb_has_eh_pred (bb))
1694 226860 : for (j = 0; ; ++j)
1695 : {
1696 680580 : unsigned int regno = EH_RETURN_DATA_REGNO (j);
1697 453720 : if (regno == INVALID_REGNUM)
1698 : break;
1699 453720 : make_hard_regno_live (regno);
1700 453720 : }
1701 :
1702 : /* Allocnos can't go in stack regs at the start of a basic block
1703 : that is reached by an abnormal edge. Likewise for registers
1704 : that are at least partly call clobbered, because caller-save,
1705 : fixup_abnormal_edges and possibly the table driven EH machinery
1706 : are not quite ready to handle such allocnos live across such
1707 : edges. */
1708 14825658 : if (bb_has_abnormal_pred (bb))
1709 : {
1710 : #ifdef STACK_REGS
1711 712007 : EXECUTE_IF_SET_IN_SPARSESET (objects_live, px)
1712 : {
1713 482509 : ira_allocno_t a = OBJECT_ALLOCNO (ira_object_id_map[px]);
1714 :
1715 482509 : ALLOCNO_NO_STACK_REG_P (a) = true;
1716 482509 : ALLOCNO_TOTAL_NO_STACK_REG_P (a) = true;
1717 : }
1718 2065482 : for (px = FIRST_STACK_REG; px <= LAST_STACK_REG; px++)
1719 1835984 : make_hard_regno_live (px);
1720 : #endif
1721 : /* No need to record conflicts for call clobbered regs if we
1722 : have nonlocal labels around, as we don't ever try to
1723 : allocate such regs in this case. */
1724 229498 : if (!cfun->has_nonlocal_label
1725 229498 : && has_abnormal_call_or_eh_pred_edge_p (bb))
1726 21550845 : for (px = 0; px < FIRST_PSEUDO_REGISTER; px++)
1727 21323994 : if (eh_edge_abi.clobbers_at_least_part_of_reg_p (px)
1728 : #ifdef REAL_PIC_OFFSET_TABLE_REGNUM
1729 : /* We should create a conflict of PIC pseudo with
1730 : PIC hard reg as PIC hard reg can have a wrong
1731 : value after jump described by the abnormal edge.
1732 : In this case we cannot allocate PIC hard reg to
1733 : PIC pseudo as PIC pseudo will also have a wrong
1734 : value. This code is not critical as LRA can fix
1735 : it but it is better to have the right allocation
1736 : earlier. */
1737 21463280 : || (px == REAL_PIC_OFFSET_TABLE_REGNUM
1738 226851 : && pic_offset_table_rtx != NULL_RTX
1739 6302 : && REGNO (pic_offset_table_rtx) >= FIRST_PSEUDO_REGISTER)
1740 : #endif
1741 : )
1742 19328433 : make_hard_regno_live (px);
1743 : }
1744 :
1745 221043393 : EXECUTE_IF_SET_IN_SPARSESET (objects_live, i)
1746 206217735 : make_object_dead (ira_object_id_map[i]);
1747 :
1748 14825658 : curr_point++;
1749 :
1750 : }
1751 : /* Propagate register pressure to upper loop tree nodes. */
1752 16988501 : if (loop_tree_node != ira_loop_tree_root)
1753 76133864 : for (i = 0; i < ira_pressure_classes_num; i++)
1754 : {
1755 60676486 : enum reg_class pclass;
1756 :
1757 60676486 : pclass = ira_pressure_classes[i];
1758 60676486 : if (loop_tree_node->reg_pressure[pclass]
1759 60676486 : > loop_tree_node->parent->reg_pressure[pclass])
1760 4339446 : loop_tree_node->parent->reg_pressure[pclass]
1761 4339446 : = loop_tree_node->reg_pressure[pclass];
1762 : /* A loop gets the calls of its subloops when they are marked for
1763 : removal. */
1764 60676486 : if (loop_tree_node->bb != NULL
1765 58140384 : && (loop_tree_node->call_crossing_pressure[pclass]
1766 58140384 : > loop_tree_node->parent->call_crossing_pressure[pclass]))
1767 33 : loop_tree_node->parent->call_crossing_pressure[pclass]
1768 33 : = loop_tree_node->call_crossing_pressure[pclass];
1769 : }
1770 16988501 : }
1771 :
1772 : /* Create and set up IRA_START_POINT_RANGES and
1773 : IRA_FINISH_POINT_RANGES. */
1774 : static void
1775 3227292 : create_start_finish_chains (void)
1776 : {
1777 3227292 : ira_object_t obj;
1778 3227292 : ira_object_iterator oi;
1779 3227292 : live_range_t r;
1780 :
1781 3227292 : ira_start_point_ranges
1782 3227292 : = (live_range_t *) ira_allocate (ira_max_point * sizeof (live_range_t));
1783 3227292 : memset (ira_start_point_ranges, 0, ira_max_point * sizeof (live_range_t));
1784 3227292 : ira_finish_point_ranges
1785 3227292 : = (live_range_t *) ira_allocate (ira_max_point * sizeof (live_range_t));
1786 3227292 : memset (ira_finish_point_ranges, 0, ira_max_point * sizeof (live_range_t));
1787 83580781 : FOR_EACH_OBJECT (obj, oi)
1788 189527179 : for (r = OBJECT_LIVE_RANGES (obj); r != NULL; r = r->next)
1789 : {
1790 109173690 : r->start_next = ira_start_point_ranges[r->start];
1791 109173690 : ira_start_point_ranges[r->start] = r;
1792 109173690 : r->finish_next = ira_finish_point_ranges[r->finish];
1793 109173690 : ira_finish_point_ranges[r->finish] = r;
1794 : }
1795 3227292 : }
1796 :
1797 : /* Rebuild IRA_START_POINT_RANGES and IRA_FINISH_POINT_RANGES after
1798 : new live ranges and program points were added as a result if new
1799 : insn generation. */
1800 : void
1801 1696169 : ira_rebuild_start_finish_chains (void)
1802 : {
1803 1696169 : ira_free (ira_finish_point_ranges);
1804 1696169 : ira_free (ira_start_point_ranges);
1805 1696169 : create_start_finish_chains ();
1806 1696169 : }
1807 :
1808 : /* Compress allocno live ranges by removing program points where
1809 : nothing happens. */
1810 : static void
1811 1531123 : remove_some_program_points_and_update_live_ranges (void)
1812 : {
1813 1531123 : unsigned i;
1814 1531123 : int n;
1815 1531123 : int *map;
1816 1531123 : ira_object_t obj;
1817 1531123 : ira_object_iterator oi;
1818 1531123 : live_range_t r, prev_r, next_r;
1819 1531123 : sbitmap_iterator sbi;
1820 1531123 : bool born_p, dead_p, prev_born_p, prev_dead_p;
1821 :
1822 1531123 : auto_sbitmap born (ira_max_point);
1823 1531123 : auto_sbitmap dead (ira_max_point);
1824 1531123 : bitmap_clear (born);
1825 1531123 : bitmap_clear (dead);
1826 36950073 : FOR_EACH_OBJECT (obj, oi)
1827 90391233 : for (r = OBJECT_LIVE_RANGES (obj); r != NULL; r = r->next)
1828 : {
1829 54972283 : ira_assert (r->start <= r->finish);
1830 54972283 : bitmap_set_bit (born, r->start);
1831 54972283 : bitmap_set_bit (dead, r->finish);
1832 : }
1833 :
1834 1531123 : auto_sbitmap born_or_dead (ira_max_point);
1835 1531123 : bitmap_ior (born_or_dead, born, dead);
1836 1531123 : map = (int *) ira_allocate (sizeof (int) * ira_max_point);
1837 1531123 : n = -1;
1838 1531123 : prev_born_p = prev_dead_p = false;
1839 69055664 : EXECUTE_IF_SET_IN_BITMAP (born_or_dead, 0, i, sbi)
1840 : {
1841 65993418 : born_p = bitmap_bit_p (born, i);
1842 65993418 : dead_p = bitmap_bit_p (dead, i);
1843 65993418 : if ((prev_born_p && ! prev_dead_p && born_p && ! dead_p)
1844 59668034 : || (prev_dead_p && ! prev_born_p && dead_p && ! born_p))
1845 16752299 : map[i] = n;
1846 : else
1847 49241119 : map[i] = ++n;
1848 65993418 : prev_born_p = born_p;
1849 65993418 : prev_dead_p = dead_p;
1850 : }
1851 :
1852 1531123 : n++;
1853 1531123 : if (internal_flag_ira_verbose > 1 && ira_dump_file != NULL)
1854 101 : fprintf (ira_dump_file, "Compressing live ranges: from %d to %d - %d%%\n",
1855 101 : ira_max_point, n, 100 * n / ira_max_point);
1856 1531123 : ira_max_point = n;
1857 :
1858 36950073 : FOR_EACH_OBJECT (obj, oi)
1859 90391233 : for (r = OBJECT_LIVE_RANGES (obj), prev_r = NULL; r != NULL; r = next_r)
1860 : {
1861 54972283 : next_r = r->next;
1862 54972283 : r->start = map[r->start];
1863 54972283 : r->finish = map[r->finish];
1864 54972283 : if (prev_r == NULL || prev_r->start > r->finish + 1)
1865 : {
1866 42220752 : prev_r = r;
1867 42220752 : continue;
1868 : }
1869 12751531 : prev_r->start = r->start;
1870 12751531 : prev_r->next = next_r;
1871 12751531 : ira_finish_live_range (r);
1872 : }
1873 :
1874 1531123 : ira_free (map);
1875 1531123 : }
1876 :
1877 : /* Print live ranges R to file F. */
1878 : void
1879 2234 : ira_print_live_range_list (FILE *f, live_range_t r)
1880 : {
1881 4821 : for (; r != NULL; r = r->next)
1882 2587 : fprintf (f, " [%d..%d]", r->start, r->finish);
1883 2234 : fprintf (f, "\n");
1884 2234 : }
1885 :
1886 : DEBUG_FUNCTION void
1887 0 : debug (live_range &ref)
1888 : {
1889 0 : ira_print_live_range_list (stderr, &ref);
1890 0 : }
1891 :
1892 : DEBUG_FUNCTION void
1893 0 : debug (live_range *ptr)
1894 : {
1895 0 : if (ptr)
1896 0 : debug (*ptr);
1897 : else
1898 0 : fprintf (stderr, "<nil>\n");
1899 0 : }
1900 :
1901 : /* Print live ranges R to stderr. */
1902 : void
1903 0 : ira_debug_live_range_list (live_range_t r)
1904 : {
1905 0 : ira_print_live_range_list (stderr, r);
1906 0 : }
1907 :
1908 : /* Print live ranges of object OBJ to file F. */
1909 : static void
1910 2043 : print_object_live_ranges (FILE *f, ira_object_t obj)
1911 : {
1912 0 : ira_print_live_range_list (f, OBJECT_LIVE_RANGES (obj));
1913 0 : }
1914 :
1915 : /* Print live ranges of allocno A to file F. */
1916 : static void
1917 2043 : print_allocno_live_ranges (FILE *f, ira_allocno_t a)
1918 : {
1919 2043 : int n = ALLOCNO_NUM_OBJECTS (a);
1920 2043 : int i;
1921 :
1922 4086 : for (i = 0; i < n; i++)
1923 : {
1924 2043 : fprintf (f, " a%d(r%d", ALLOCNO_NUM (a), ALLOCNO_REGNO (a));
1925 2043 : if (n > 1)
1926 0 : fprintf (f, " [%d]", i);
1927 2043 : fprintf (f, "):");
1928 2043 : print_object_live_ranges (f, ALLOCNO_OBJECT (a, i));
1929 : }
1930 2043 : }
1931 :
1932 : /* Print live ranges of allocno A to stderr. */
1933 : void
1934 0 : ira_debug_allocno_live_ranges (ira_allocno_t a)
1935 : {
1936 0 : print_allocno_live_ranges (stderr, a);
1937 0 : }
1938 :
1939 : /* Print live ranges of all allocnos to file F. */
1940 : static void
1941 202 : print_live_ranges (FILE *f)
1942 : {
1943 202 : ira_allocno_t a;
1944 202 : ira_allocno_iterator ai;
1945 :
1946 2245 : FOR_EACH_ALLOCNO (a, ai)
1947 2043 : print_allocno_live_ranges (f, a);
1948 202 : }
1949 :
1950 : /* Print live ranges of all allocnos to stderr. */
1951 : void
1952 0 : ira_debug_live_ranges (void)
1953 : {
1954 0 : print_live_ranges (stderr);
1955 0 : }
1956 :
1957 : /* The main entry function creates live ranges, set up
1958 : CONFLICT_HARD_REGS and TOTAL_CONFLICT_HARD_REGS for objects, and
1959 : calculate register pressure info. */
1960 : void
1961 1531123 : ira_create_allocno_live_ranges (void)
1962 : {
1963 1531123 : objects_live = sparseset_alloc (ira_objects_num);
1964 1531123 : allocnos_processed = sparseset_alloc (ira_allocnos_num);
1965 1531123 : curr_point = 0;
1966 1531123 : last_call_num = 0;
1967 1531123 : allocno_saved_at_call
1968 1531123 : = (int *) ira_allocate (ira_allocnos_num * sizeof (int));
1969 1531123 : memset (allocno_saved_at_call, 0, ira_allocnos_num * sizeof (int));
1970 1531123 : ira_traverse_loop_tree (true, ira_loop_tree_root, NULL,
1971 : process_bb_node_lives);
1972 1531123 : ira_max_point = curr_point;
1973 1531123 : create_start_finish_chains ();
1974 1531123 : if (internal_flag_ira_verbose > 2 && ira_dump_file != NULL)
1975 101 : print_live_ranges (ira_dump_file);
1976 : /* Clean up. */
1977 1531123 : ira_free (allocno_saved_at_call);
1978 1531123 : sparseset_free (objects_live);
1979 1531123 : sparseset_free (allocnos_processed);
1980 1531123 : }
1981 :
1982 : /* Compress allocno live ranges. */
1983 : void
1984 1531123 : ira_compress_allocno_live_ranges (void)
1985 : {
1986 1531123 : remove_some_program_points_and_update_live_ranges ();
1987 1531123 : ira_rebuild_start_finish_chains ();
1988 1531123 : if (internal_flag_ira_verbose > 2 && ira_dump_file != NULL)
1989 : {
1990 101 : fprintf (ira_dump_file, "Ranges after the compression:\n");
1991 101 : print_live_ranges (ira_dump_file);
1992 : }
1993 1531123 : }
1994 :
1995 : /* Free arrays IRA_START_POINT_RANGES and IRA_FINISH_POINT_RANGES. */
1996 : void
1997 1531123 : ira_finish_allocno_live_ranges (void)
1998 : {
1999 1531123 : ira_free (ira_finish_point_ranges);
2000 1531123 : ira_free (ira_start_point_ranges);
2001 1531123 : }
|