Branch data Line data Source code
1 : : /* Build live ranges for pseudos.
2 : : Copyright (C) 2010-2025 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 : :
22 : : /* This file contains code to build pseudo live-ranges (analogous
23 : : structures used in IRA, so read comments about the live-ranges
24 : : there) and other info necessary for other passes to assign
25 : : hard-registers to pseudos, coalesce the spilled pseudos, and assign
26 : : stack memory slots to spilled pseudos. */
27 : :
28 : : #include "config.h"
29 : : #include "system.h"
30 : : #include "coretypes.h"
31 : : #include "backend.h"
32 : : #include "rtl.h"
33 : : #include "tree.h"
34 : : #include "predict.h"
35 : : #include "df.h"
36 : : #include "memmodel.h"
37 : : #include "tm_p.h"
38 : : #include "insn-config.h"
39 : : #include "regs.h"
40 : : #include "ira.h"
41 : : #include "ira-int.h"
42 : : #include "recog.h"
43 : : #include "cfganal.h"
44 : : #include "sparseset.h"
45 : : #include "lra-int.h"
46 : : #include "target.h"
47 : : #include "function-abi.h"
48 : :
49 : : /* Program points are enumerated by numbers from range
50 : : 0..LRA_LIVE_MAX_POINT-1. There are approximately two times more
51 : : program points than insns. Program points are places in the
52 : : program where liveness info can be changed. In most general case
53 : : (there are more complicated cases too) some program points
54 : : correspond to places where input operand dies and other ones
55 : : correspond to places where output operands are born. */
56 : : int lra_live_max_point;
57 : :
58 : : /* Accumulated execution frequency of all references for each hard
59 : : register. */
60 : : int lra_hard_reg_usage[FIRST_PSEUDO_REGISTER];
61 : :
62 : : /* A global flag whose true value says to build live ranges for all
63 : : pseudos, otherwise the live ranges only for pseudos got memory is
64 : : build. True value means also building copies and setting up hard
65 : : register preferences. The complete info is necessary for
66 : : assignment, rematerialization and spill to register passes. The
67 : : complete info is not needed for the coalescing and spill to memory
68 : : passes. */
69 : : static bool complete_info_p;
70 : :
71 : : /* Pseudos live at current point in the RTL scan. */
72 : : static sparseset pseudos_live;
73 : :
74 : : /* Pseudos probably living through calls and setjumps. As setjump is
75 : : a call too, if a bit in PSEUDOS_LIVE_THROUGH_SETJUMPS is set up
76 : : then the corresponding bit in PSEUDOS_LIVE_THROUGH_CALLS is set up
77 : : too. These data are necessary for cases when only one subreg of a
78 : : multi-reg pseudo is set up after a call. So we decide it is
79 : : probably live when traversing bb backward. We are sure about
80 : : living when we see its usage or definition of the pseudo. */
81 : : static sparseset pseudos_live_through_calls;
82 : : static sparseset pseudos_live_through_setjumps;
83 : :
84 : : /* Set of hard regs (except eliminable ones) currently live. */
85 : : static HARD_REG_SET hard_regs_live;
86 : :
87 : : /* Set of pseudos and hard registers start living/dying in the current
88 : : insn. These sets are used to update REG_DEAD and REG_UNUSED notes
89 : : in the insn. */
90 : : static sparseset start_living, start_dying;
91 : :
92 : : /* Set of pseudos and hard regs dead and unused in the current
93 : : insn. */
94 : : static sparseset unused_set, dead_set;
95 : :
96 : : /* Bitmap used for holding intermediate bitmap operation results. */
97 : : static bitmap_head temp_bitmap;
98 : :
99 : : /* Pool for pseudo live ranges. */
100 : : static object_allocator<lra_live_range> lra_live_range_pool ("live ranges");
101 : :
102 : : /* Free live range list LR. */
103 : : static void
104 : 308786968 : free_live_range_list (lra_live_range_t lr)
105 : : {
106 : 308786968 : lra_live_range_t next;
107 : :
108 : 403441639 : while (lr != NULL)
109 : : {
110 : 94654671 : next = lr->next;
111 : 94654671 : lra_live_range_pool.remove (lr);
112 : 94654671 : lr = next;
113 : : }
114 : 308786968 : }
115 : :
116 : : /* Create and return pseudo live range with given attributes. */
117 : : static lra_live_range_t
118 : 104630456 : create_live_range (int regno, int start, int finish, lra_live_range_t next)
119 : : {
120 : 0 : lra_live_range_t p = lra_live_range_pool.allocate ();
121 : 104630456 : p->regno = regno;
122 : 104630456 : p->start = start;
123 : 104630456 : p->finish = finish;
124 : 104630456 : p->next = next;
125 : 104630456 : return p;
126 : : }
127 : :
128 : : /* Copy live range R and return the result. */
129 : : static lra_live_range_t
130 : 1972200 : copy_live_range (lra_live_range_t r)
131 : : {
132 : 1972200 : return new (lra_live_range_pool) lra_live_range (*r);
133 : : }
134 : :
135 : : /* Copy live range list given by its head R and return the result. */
136 : : lra_live_range_t
137 : 1298046 : lra_copy_live_range_list (lra_live_range_t r)
138 : : {
139 : 1298046 : lra_live_range_t p, first, *chain;
140 : :
141 : 1298046 : first = NULL;
142 : 3270246 : for (chain = &first; r != NULL; r = r->next)
143 : : {
144 : 1972200 : p = copy_live_range (r);
145 : 1972200 : *chain = p;
146 : 1972200 : chain = &p->next;
147 : : }
148 : 1298046 : return first;
149 : : }
150 : :
151 : : /* Merge *non-intersected* ranges R1 and R2 and returns the result.
152 : : The function maintains the order of ranges and tries to minimize
153 : : size of the result range list. Ranges R1 and R2 may not be used
154 : : after the call. */
155 : : lra_live_range_t
156 : 1298046 : lra_merge_live_ranges (lra_live_range_t r1, lra_live_range_t r2)
157 : : {
158 : 1298046 : lra_live_range_t first, last;
159 : :
160 : 1298046 : if (r1 == NULL)
161 : : return r2;
162 : 572530 : if (r2 == NULL)
163 : : return r1;
164 : 5419356 : for (first = last = NULL; r1 != NULL && r2 != NULL;)
165 : : {
166 : 4846826 : if (r1->start < r2->start)
167 : 352081 : std::swap (r1, r2);
168 : :
169 : 4846826 : if (r1->start == r2->finish + 1)
170 : : {
171 : : /* Joint ranges: merge r1 and r2 into r1. */
172 : 39693 : r1->start = r2->start;
173 : 39693 : lra_live_range_t temp = r2;
174 : 39693 : r2 = r2->next;
175 : 39693 : lra_live_range_pool.remove (temp);
176 : : }
177 : : else
178 : : {
179 : 4807133 : gcc_assert (r2->finish + 1 < r1->start);
180 : : /* Add r1 to the result. */
181 : 4807133 : if (first == NULL)
182 : : first = last = r1;
183 : : else
184 : : {
185 : 4238893 : last->next = r1;
186 : 4238893 : last = r1;
187 : : }
188 : 4807133 : r1 = r1->next;
189 : : }
190 : : }
191 : 572530 : if (r1 != NULL)
192 : : {
193 : 14536 : if (first == NULL)
194 : : first = r1;
195 : : else
196 : 10246 : last->next = r1;
197 : : }
198 : : else
199 : : {
200 : 557994 : lra_assert (r2 != NULL);
201 : 557994 : if (first == NULL)
202 : : first = r2;
203 : : else
204 : 557994 : last->next = r2;
205 : : }
206 : : return first;
207 : : }
208 : :
209 : : /* Return TRUE if live ranges R1 and R2 intersect. */
210 : : bool
211 : 25255350 : lra_intersected_live_ranges_p (lra_live_range_t r1, lra_live_range_t r2)
212 : : {
213 : : /* Remember the live ranges are always kept ordered. */
214 : 40376733 : while (r1 != NULL && r2 != NULL)
215 : : {
216 : 39802216 : if (r1->start > r2->finish)
217 : 13855237 : r1 = r1->next;
218 : 25946979 : else if (r2->start > r1->finish)
219 : 1266146 : r2 = r2->next;
220 : : else
221 : : return true;
222 : : }
223 : : return false;
224 : : }
225 : :
226 : : enum point_type {
227 : : DEF_POINT,
228 : : USE_POINT
229 : : };
230 : :
231 : : /* Return TRUE if set A contains a pseudo register, otherwise, return FALSE. */
232 : : static bool
233 : 742882254 : sparseset_contains_pseudos_p (sparseset a)
234 : : {
235 : 742882254 : int regno;
236 : 875470750 : EXECUTE_IF_SET_IN_SPARSESET (a, regno)
237 : 319507804 : if (!HARD_REGISTER_NUM_P (regno))
238 : : return true;
239 : : return false;
240 : : }
241 : :
242 : : /* Mark pseudo REGNO as living or dying at program point POINT, depending on
243 : : whether TYPE is a definition or a use. If this is the first reference to
244 : : REGNO that we've encountered, then create a new live range for it. */
245 : :
246 : : static void
247 : 1214547026 : update_pseudo_point (int regno, int point, enum point_type type)
248 : : {
249 : 1214547026 : lra_live_range_t p;
250 : :
251 : : /* Don't compute points for hard registers. */
252 : 1214547026 : if (HARD_REGISTER_NUM_P (regno))
253 : : return;
254 : :
255 : 1110329552 : if (complete_info_p || lra_get_regno_hard_regno (regno) < 0)
256 : : {
257 : 1095540938 : if (type == DEF_POINT)
258 : : {
259 : 473300460 : if (sparseset_bit_p (pseudos_live, regno))
260 : : {
261 : 473300460 : p = lra_reg_info[regno].live_ranges;
262 : 473300460 : lra_assert (p != NULL);
263 : 473300460 : p->finish = point;
264 : : }
265 : : }
266 : : else /* USE_POINT */
267 : : {
268 : 622240478 : if (!sparseset_bit_p (pseudos_live, regno)
269 : 622240478 : && ((p = lra_reg_info[regno].live_ranges) == NULL
270 : 389905143 : || (p->finish != point && p->finish + 1 != point)))
271 : 104630456 : lra_reg_info[regno].live_ranges
272 : 104630456 : = create_live_range (regno, point, -1, p);
273 : : }
274 : : }
275 : : }
276 : :
277 : : /* The corresponding bitmaps of BB currently being processed. */
278 : : static bitmap bb_killed_pseudos, bb_gen_pseudos;
279 : :
280 : : /* Record hard register REGNO as now being live. It updates
281 : : living hard regs and START_LIVING. */
282 : : static void
283 : 221246676 : make_hard_regno_live (int regno)
284 : : {
285 : 221246676 : lra_assert (HARD_REGISTER_NUM_P (regno));
286 : 221246676 : if (TEST_HARD_REG_BIT (hard_regs_live, regno)
287 : 221246676 : || TEST_HARD_REG_BIT (eliminable_regset, regno))
288 : : return;
289 : 123971113 : SET_HARD_REG_BIT (hard_regs_live, regno);
290 : 123971113 : sparseset_set_bit (start_living, regno);
291 : 123971113 : if (fixed_regs[regno] || TEST_HARD_REG_BIT (hard_regs_spilled_into, regno))
292 : 72333175 : bitmap_set_bit (bb_gen_pseudos, regno);
293 : : }
294 : :
295 : : /* Process the definition of hard register REGNO. This updates
296 : : hard_regs_live, START_DYING and conflict hard regs for living
297 : : pseudos. */
298 : : static void
299 : 122339477 : make_hard_regno_dead (int regno)
300 : : {
301 : 122339477 : if (TEST_HARD_REG_BIT (eliminable_regset, regno))
302 : : return;
303 : :
304 : 122338572 : lra_assert (HARD_REGISTER_NUM_P (regno));
305 : 122338572 : unsigned int i;
306 : 1284300452 : EXECUTE_IF_SET_IN_SPARSESET (pseudos_live, i)
307 : 1161961880 : SET_HARD_REG_BIT (lra_reg_info[i].conflict_hard_regs, regno);
308 : :
309 : 122338572 : if (! TEST_HARD_REG_BIT (hard_regs_live, regno))
310 : : return;
311 : 122337843 : CLEAR_HARD_REG_BIT (hard_regs_live, regno);
312 : 122337843 : sparseset_set_bit (start_dying, regno);
313 : 122337843 : if (fixed_regs[regno] || TEST_HARD_REG_BIT (hard_regs_spilled_into, regno))
314 : : {
315 : 72333216 : bitmap_clear_bit (bb_gen_pseudos, regno);
316 : 72333216 : bitmap_set_bit (bb_killed_pseudos, regno);
317 : : }
318 : : }
319 : :
320 : : /* Mark pseudo REGNO as now being live and update START_LIVING. */
321 : : static void
322 : 633170169 : mark_pseudo_live (int regno)
323 : : {
324 : 633170169 : lra_assert (!HARD_REGISTER_NUM_P (regno));
325 : 633170169 : if (sparseset_bit_p (pseudos_live, regno))
326 : : return;
327 : :
328 : 483046544 : sparseset_set_bit (pseudos_live, regno);
329 : 483046544 : sparseset_set_bit (start_living, regno);
330 : : }
331 : :
332 : : /* Mark pseudo REGNO as now being dead and update START_DYING. */
333 : : static void
334 : 483046544 : mark_pseudo_dead (int regno)
335 : : {
336 : 483046544 : lra_assert (!HARD_REGISTER_NUM_P (regno));
337 : 483046544 : lra_reg_info[regno].conflict_hard_regs |= hard_regs_live;
338 : 483046544 : if (!sparseset_bit_p (pseudos_live, regno))
339 : : return;
340 : :
341 : 483046544 : sparseset_clear_bit (pseudos_live, regno);
342 : 483046544 : sparseset_set_bit (start_dying, regno);
343 : : }
344 : :
345 : : /* Mark register REGNO (pseudo or hard register) in MODE as being live
346 : : and update BB_GEN_PSEUDOS. */
347 : : static void
348 : 348446507 : mark_regno_live (int regno, machine_mode mode)
349 : : {
350 : 348446507 : int last;
351 : :
352 : 348446507 : if (HARD_REGISTER_NUM_P (regno))
353 : : {
354 : 200746857 : for (last = end_hard_regno (mode, regno); regno < last; regno++)
355 : 100668174 : make_hard_regno_live (regno);
356 : : }
357 : : else
358 : : {
359 : 248367824 : mark_pseudo_live (regno);
360 : 248367824 : bitmap_set_bit (bb_gen_pseudos, regno);
361 : : }
362 : 348446507 : }
363 : :
364 : :
365 : : /* Mark register REGNO (pseudo or hard register) in MODE as being dead
366 : : and update BB_GEN_PSEUDOS and BB_KILLED_PSEUDOS. */
367 : : static void
368 : 142625380 : mark_regno_dead (int regno, machine_mode mode)
369 : : {
370 : 142625380 : int last;
371 : :
372 : 142625380 : if (HARD_REGISTER_NUM_P (regno))
373 : : {
374 : 74018918 : for (last = end_hard_regno (mode, regno); regno < last; regno++)
375 : 37239235 : make_hard_regno_dead (regno);
376 : : }
377 : : else
378 : : {
379 : 105845697 : mark_pseudo_dead (regno);
380 : 105845697 : bitmap_clear_bit (bb_gen_pseudos, regno);
381 : 105845697 : bitmap_set_bit (bb_killed_pseudos, regno);
382 : : }
383 : 142625380 : }
384 : :
385 : :
386 : :
387 : : /* This page contains code for making global live analysis of pseudos.
388 : : The code works only when pseudo live info is changed on a BB
389 : : border. That might be a consequence of some global transformations
390 : : in LRA, e.g. PIC pseudo reuse or rematerialization. */
391 : :
392 : : /* Structure describing local BB data used for pseudo
393 : : live-analysis. */
394 : : class bb_data_pseudos
395 : : {
396 : : public:
397 : : /* Basic block about which the below data are. */
398 : : basic_block bb;
399 : : bitmap_head killed_pseudos; /* pseudos killed in the BB. */
400 : : bitmap_head gen_pseudos; /* pseudos generated in the BB. */
401 : : };
402 : :
403 : : /* Array for all BB data. Indexed by the corresponding BB index. */
404 : : typedef class bb_data_pseudos *bb_data_t;
405 : :
406 : : /* All basic block data are referred through the following array. */
407 : : static bb_data_t bb_data;
408 : :
409 : : /* Two small functions for access to the bb data. */
410 : : static inline bb_data_t
411 : 70301533 : get_bb_data (basic_block bb)
412 : : {
413 : 70301533 : return &bb_data[(bb)->index];
414 : : }
415 : :
416 : : static inline bb_data_t
417 : 7213513 : get_bb_data_by_index (int index)
418 : : {
419 : 7213513 : return &bb_data[index];
420 : : }
421 : :
422 : : /* Bitmap with all hard regs. */
423 : : static bitmap_head all_hard_regs_bitmap;
424 : :
425 : : /* The transfer function used by the DF equation solver to propagate
426 : : live info through block with BB_INDEX according to the following
427 : : equation:
428 : :
429 : : bb.livein = (bb.liveout - bb.kill) OR bb.gen
430 : : */
431 : : static bool
432 : 7213513 : live_trans_fun (int bb_index)
433 : : {
434 : 7213513 : basic_block bb = get_bb_data_by_index (bb_index)->bb;
435 : 7213513 : bitmap bb_liveout = df_get_live_out (bb);
436 : 7213513 : bitmap bb_livein = df_get_live_in (bb);
437 : 7213513 : bb_data_t bb_info = get_bb_data (bb);
438 : :
439 : 7213513 : bitmap_and_compl (&temp_bitmap, bb_liveout, &all_hard_regs_bitmap);
440 : 7213513 : return bitmap_ior_and_compl (bb_livein, &bb_info->gen_pseudos,
441 : 7213513 : &temp_bitmap, &bb_info->killed_pseudos);
442 : : }
443 : :
444 : : /* The confluence function used by the DF equation solver to set up
445 : : live info for a block BB without predecessor. */
446 : : static void
447 : 314529 : live_con_fun_0 (basic_block bb)
448 : : {
449 : 314529 : bitmap_and_into (df_get_live_out (bb), &all_hard_regs_bitmap);
450 : 314529 : }
451 : :
452 : : /* The confluence function used by the DF equation solver to propagate
453 : : live info from successor to predecessor on edge E according to the
454 : : following equation:
455 : :
456 : : bb.liveout = 0 for entry block | OR (livein of successors)
457 : : */
458 : : static bool
459 : 10491432 : live_con_fun_n (edge e)
460 : : {
461 : 10491432 : basic_block bb = e->src;
462 : 10491432 : basic_block dest = e->dest;
463 : 10491432 : bitmap bb_liveout = df_get_live_out (bb);
464 : 10491432 : bitmap dest_livein = df_get_live_in (dest);
465 : :
466 : 10491432 : return bitmap_ior_and_compl_into (bb_liveout,
467 : 10491432 : dest_livein, &all_hard_regs_bitmap);
468 : : }
469 : :
470 : : /* Indexes of all function blocks. */
471 : : static bitmap_head all_blocks;
472 : :
473 : : /* Allocate and initialize data needed for global pseudo live
474 : : analysis. */
475 : : static void
476 : 1431622 : initiate_live_solver (void)
477 : : {
478 : 1431622 : bitmap_initialize (&all_hard_regs_bitmap, ®_obstack);
479 : 1431622 : bitmap_set_range (&all_hard_regs_bitmap, 0, FIRST_PSEUDO_REGISTER);
480 : 1431622 : bb_data = XNEWVEC (class bb_data_pseudos, last_basic_block_for_fn (cfun));
481 : 1431622 : bitmap_initialize (&all_blocks, ®_obstack);
482 : :
483 : 1431622 : basic_block bb;
484 : 18000199 : FOR_ALL_BB_FN (bb, cfun)
485 : : {
486 : 16568577 : bb_data_t bb_info = get_bb_data (bb);
487 : 16568577 : bb_info->bb = bb;
488 : 16568577 : bitmap_initialize (&bb_info->killed_pseudos, ®_obstack);
489 : 16568577 : bitmap_initialize (&bb_info->gen_pseudos, ®_obstack);
490 : 16568577 : bitmap_set_bit (&all_blocks, bb->index);
491 : : }
492 : 1431622 : }
493 : :
494 : : /* Free all data needed for global pseudo live analysis. */
495 : : static void
496 : 1431622 : finish_live_solver (void)
497 : : {
498 : 1431622 : basic_block bb;
499 : :
500 : 1431622 : bitmap_clear (&all_blocks);
501 : 18000199 : FOR_ALL_BB_FN (bb, cfun)
502 : : {
503 : 16568577 : bb_data_t bb_info = get_bb_data (bb);
504 : 16568577 : bitmap_clear (&bb_info->killed_pseudos);
505 : 16568577 : bitmap_clear (&bb_info->gen_pseudos);
506 : : }
507 : 1431622 : free (bb_data);
508 : 1431622 : bitmap_clear (&all_hard_regs_bitmap);
509 : 1431622 : }
510 : :
511 : :
512 : :
513 : : /* Insn currently scanned. */
514 : : static rtx_insn *curr_insn;
515 : : /* The insn data. */
516 : : static lra_insn_recog_data_t curr_id;
517 : : /* The insn static data. */
518 : : static struct lra_static_insn_data *curr_static_id;
519 : :
520 : : /* Vec containing execution frequencies of program points. */
521 : : static vec<int> point_freq_vec;
522 : :
523 : : /* The start of the above vector elements. */
524 : : int *lra_point_freq;
525 : :
526 : : /* Increment the current program point POINT to the next point which has
527 : : execution frequency FREQ. */
528 : : static void
529 : 210833558 : next_program_point (int &point, int freq)
530 : : {
531 : 210833558 : point_freq_vec.safe_push (freq);
532 : 210833558 : lra_point_freq = point_freq_vec.address ();
533 : 210833558 : point++;
534 : 210833558 : }
535 : :
536 : : /* Update the preference of HARD_REGNO for pseudo REGNO by PROFIT. */
537 : : void
538 : 14432688 : lra_setup_reload_pseudo_preferenced_hard_reg (int regno,
539 : : int hard_regno, int profit)
540 : : {
541 : 14432688 : lra_assert (regno >= lra_constraint_new_regno_start);
542 : 14432688 : if (lra_reg_info[regno].preferred_hard_regno1 == hard_regno)
543 : 2563403 : lra_reg_info[regno].preferred_hard_regno_profit1 += profit;
544 : 11869285 : else if (lra_reg_info[regno].preferred_hard_regno2 == hard_regno)
545 : 82338 : lra_reg_info[regno].preferred_hard_regno_profit2 += profit;
546 : 11786947 : else if (lra_reg_info[regno].preferred_hard_regno1 < 0)
547 : : {
548 : 9314070 : lra_reg_info[regno].preferred_hard_regno1 = hard_regno;
549 : 9314070 : lra_reg_info[regno].preferred_hard_regno_profit1 = profit;
550 : : }
551 : 2472877 : else if (lra_reg_info[regno].preferred_hard_regno2 < 0
552 : 67256 : || profit > lra_reg_info[regno].preferred_hard_regno_profit2)
553 : : {
554 : 2429113 : lra_reg_info[regno].preferred_hard_regno2 = hard_regno;
555 : 2429113 : lra_reg_info[regno].preferred_hard_regno_profit2 = profit;
556 : : }
557 : : else
558 : : return;
559 : : /* Keep the 1st hard regno as more profitable. */
560 : 14388924 : if (lra_reg_info[regno].preferred_hard_regno1 >= 0
561 : 14388924 : && lra_reg_info[regno].preferred_hard_regno2 >= 0
562 : 2590210 : && (lra_reg_info[regno].preferred_hard_regno_profit2
563 : 2590210 : > lra_reg_info[regno].preferred_hard_regno_profit1))
564 : : {
565 : 97584 : std::swap (lra_reg_info[regno].preferred_hard_regno1,
566 : : lra_reg_info[regno].preferred_hard_regno2);
567 : 97584 : std::swap (lra_reg_info[regno].preferred_hard_regno_profit1,
568 : : lra_reg_info[regno].preferred_hard_regno_profit2);
569 : : }
570 : 14388924 : if (lra_dump_file != NULL)
571 : : {
572 : 232 : if ((hard_regno = lra_reg_info[regno].preferred_hard_regno1) >= 0)
573 : 232 : fprintf (lra_dump_file,
574 : : " Hard reg %d is preferable by r%d with profit %d\n",
575 : : hard_regno, regno,
576 : : lra_reg_info[regno].preferred_hard_regno_profit1);
577 : 232 : if ((hard_regno = lra_reg_info[regno].preferred_hard_regno2) >= 0)
578 : 85 : fprintf (lra_dump_file,
579 : : " Hard reg %d is preferable by r%d with profit %d\n",
580 : : hard_regno, regno,
581 : : lra_reg_info[regno].preferred_hard_regno_profit2);
582 : : }
583 : : }
584 : :
585 : : /* Check whether REGNO lives through calls and setjmps and clear
586 : : the corresponding bits in PSEUDOS_LIVE_THROUGH_CALLS and
587 : : PSEUDOS_LIVE_THROUGH_SETJUMPS. All calls in the region described
588 : : by PSEUDOS_LIVE_THROUGH_CALLS have the given ABI. */
589 : :
590 : : static inline void
591 : 438325600 : check_pseudos_live_through_calls (int regno, const function_abi &abi)
592 : : {
593 : 438325600 : if (! sparseset_bit_p (pseudos_live_through_calls, regno))
594 : : return;
595 : :
596 : 94478733 : machine_mode mode = PSEUDO_REGNO_MODE (regno);
597 : :
598 : 94478733 : sparseset_clear_bit (pseudos_live_through_calls, regno);
599 : 94478733 : lra_reg_info[regno].conflict_hard_regs |= abi.mode_clobbers (mode);
600 : 94478733 : if (! sparseset_bit_p (pseudos_live_through_setjumps, regno))
601 : : return;
602 : 6860 : sparseset_clear_bit (pseudos_live_through_setjumps, regno);
603 : : /* Don't allocate pseudos that cross setjmps or any call, if this
604 : : function receives a nonlocal goto. */
605 : 6860 : SET_HARD_REG_SET (lra_reg_info[regno].conflict_hard_regs);
606 : : }
607 : :
608 : : /* Return true if insn REG is an early clobber operand in alternative
609 : : NALT. Negative NALT means that we don't know the current insn
610 : : alternative. So assume the worst. */
611 : : static inline bool
612 : 364138928 : reg_early_clobber_p (const struct lra_insn_reg *reg, int n_alt)
613 : : {
614 : 364138928 : return (n_alt == LRA_UNKNOWN_ALT
615 : 364138928 : ? reg->early_clobber_alts != 0
616 : : : (n_alt != LRA_NON_CLOBBERED_ALT
617 : 348259258 : && TEST_BIT (reg->early_clobber_alts, n_alt)));
618 : : }
619 : :
620 : : /* Clear pseudo REGNO in SET or all hard registers of REGNO in MODE in SET. */
621 : : static void
622 : 145282334 : clear_sparseset_regnos (sparseset set, int regno, enum machine_mode mode)
623 : : {
624 : 145282334 : if (regno >= FIRST_PSEUDO_REGISTER)
625 : : {
626 : 79983345 : sparseset_clear_bit (dead_set, regno);
627 : 79983345 : return;
628 : : }
629 : 130833550 : for (int last = end_hard_regno (mode, regno); regno < last; regno++)
630 : 65534561 : sparseset_clear_bit (set, regno);
631 : : }
632 : :
633 : : /* Return true if pseudo REGNO is in SET or all hard registers of REGNO in MODE
634 : : are in SET. */
635 : : static bool
636 : 148670507 : regnos_in_sparseset_p (sparseset set, int regno, enum machine_mode mode)
637 : : {
638 : 148670507 : if (regno >= FIRST_PSEUDO_REGISTER)
639 : 83167466 : return sparseset_bit_p (dead_set, regno);
640 : 131037602 : for (int last = end_hard_regno (mode, regno); regno < last; regno++)
641 : 65738613 : if (!sparseset_bit_p (set, regno))
642 : : return false;
643 : : return true;
644 : : }
645 : :
646 : : /* Process insns of the basic block BB to update pseudo live ranges,
647 : : pseudo hard register conflicts, and insn notes. We do it on
648 : : backward scan of BB insns. CURR_POINT is the program point where
649 : : BB ends. The function updates this counter and returns in
650 : : CURR_POINT the program point where BB starts. The function also
651 : : does local live info updates and can delete the dead insns if
652 : : DEAD_INSN_P. It returns true if pseudo live info was
653 : : changed at the BB start. */
654 : : static bool
655 : 29950796 : process_bb_lives (basic_block bb, int &curr_point, bool dead_insn_p)
656 : : {
657 : 29950796 : int i, regno, freq;
658 : 29950796 : unsigned int j;
659 : 29950796 : bitmap_iterator bi;
660 : 29950796 : bitmap reg_live_out;
661 : 29950796 : unsigned int px;
662 : 29950796 : rtx_insn *next;
663 : 29950796 : rtx link, *link_loc;
664 : 29950796 : bool need_curr_point_incr;
665 : : /* Only has a meaningful value once we've seen a call. */
666 : 29950796 : function_abi last_call_abi = default_function_abi;
667 : :
668 : 29950796 : reg_live_out = df_get_live_out (bb);
669 : 29950796 : sparseset_clear (pseudos_live);
670 : 29950796 : sparseset_clear (pseudos_live_through_calls);
671 : 29950796 : sparseset_clear (pseudos_live_through_setjumps);
672 : 59901592 : REG_SET_TO_HARD_REG_SET (hard_regs_live, reg_live_out);
673 : 29950796 : hard_regs_live &= ~eliminable_regset;
674 : 414753141 : EXECUTE_IF_SET_IN_BITMAP (reg_live_out, FIRST_PSEUDO_REGISTER, j, bi)
675 : : {
676 : 384802345 : update_pseudo_point (j, curr_point, USE_POINT);
677 : 384802345 : mark_pseudo_live (j);
678 : : }
679 : :
680 : 29950796 : bb_gen_pseudos = &get_bb_data (bb)->gen_pseudos;
681 : 29950796 : bb_killed_pseudos = &get_bb_data (bb)->killed_pseudos;
682 : 29950796 : bitmap_clear (bb_gen_pseudos);
683 : 29950796 : bitmap_clear (bb_killed_pseudos);
684 : 29950796 : freq = REG_FREQ_FROM_BB (bb);
685 : :
686 : 29950796 : if (lra_dump_file != NULL)
687 : 539 : fprintf (lra_dump_file, " BB %d\n", bb->index);
688 : :
689 : : /* Scan the code of this basic block, noting which pseudos and hard
690 : : regs are born or die.
691 : :
692 : : Note that this loop treats uninitialized values as live until the
693 : : beginning of the block. For example, if an instruction uses
694 : : (reg:DI foo), and only (subreg:SI (reg:DI foo) 0) is ever set,
695 : : FOO will remain live until the beginning of the block. Likewise
696 : : if FOO is not set at all. This is unnecessarily pessimistic, but
697 : : it probably doesn't matter much in practice. */
698 : 815499324 : FOR_BB_INSNS_REVERSE_SAFE (bb, curr_insn, next)
699 : : {
700 : 377798866 : bool call_p;
701 : 377798866 : int n_alt, dst_regno, src_regno;
702 : 377798866 : rtx set;
703 : 377798866 : struct lra_insn_reg *reg;
704 : :
705 : 377798866 : if (!NONDEBUG_INSN_P (curr_insn))
706 : 171400522 : continue;
707 : :
708 : 206398344 : curr_id = lra_get_insn_recog_data (curr_insn);
709 : 206398344 : curr_static_id = curr_id->insn_static_data;
710 : 206398344 : n_alt = curr_id->used_insn_alternative;
711 : 206398344 : if (lra_dump_file != NULL)
712 : 2561 : fprintf (lra_dump_file, " Insn %u: point = %d, n_alt = %d\n",
713 : 2561 : INSN_UID (curr_insn), curr_point, n_alt);
714 : :
715 : 206398344 : set = single_set (curr_insn);
716 : :
717 : 206398344 : if (dead_insn_p && set != NULL_RTX
718 : 161136662 : && REG_P (SET_DEST (set)) && !HARD_REGISTER_P (SET_DEST (set))
719 : 84217556 : && find_reg_note (curr_insn, REG_EH_REGION, NULL_RTX) == NULL_RTX
720 : 83979918 : && ! may_trap_p (PATTERN (curr_insn))
721 : : /* Don't do premature remove of pic offset pseudo as we can
722 : : start to use it after some reload generation. */
723 : 281865285 : && (pic_offset_table_rtx == NULL_RTX
724 : 8821121 : || pic_offset_table_rtx != SET_DEST (set)))
725 : : {
726 : 75401864 : bool remove_p = true;
727 : :
728 : 75946468 : for (reg = curr_id->regs; reg != NULL; reg = reg->next)
729 : 75895235 : if (reg->type != OP_IN
730 : 75895235 : && (reg->regno < FIRST_PSEUDO_REGISTER
731 : 75401957 : ? TEST_HARD_REG_BIT (hard_regs_live, reg->regno)
732 : 75401955 : : sparseset_bit_p (pseudos_live, reg->regno)))
733 : : {
734 : : remove_p = false;
735 : : break;
736 : : }
737 : 76553041 : for (reg = curr_static_id->hard_regs; reg != NULL; reg = reg->next)
738 : 15009848 : if (reg->type != OP_IN)
739 : : {
740 : : remove_p = false;
741 : : break;
742 : : }
743 : :
744 : 75401864 : if (remove_p && ! volatile_refs_p (PATTERN (curr_insn)))
745 : : {
746 : 44156 : dst_regno = REGNO (SET_DEST (set));
747 : 44156 : if (lra_dump_file != NULL)
748 : 0 : fprintf (lra_dump_file, " Deleting dead insn %u\n",
749 : 0 : INSN_UID (curr_insn));
750 : 44156 : lra_set_insn_deleted (curr_insn);
751 : 44156 : if (lra_reg_info[dst_regno].nrefs == 0)
752 : : {
753 : : /* There might be some debug insns with the pseudo. */
754 : 5440 : unsigned int uid;
755 : 5440 : rtx_insn *insn;
756 : :
757 : 5440 : bitmap_copy (&temp_bitmap, &lra_reg_info[dst_regno].insn_bitmap);
758 : 5647 : EXECUTE_IF_SET_IN_BITMAP (&temp_bitmap, 0, uid, bi)
759 : : {
760 : 207 : insn = lra_insn_recog_data[uid]->insn;
761 : 207 : lra_substitute_pseudo_within_insn (insn, dst_regno,
762 : : SET_SRC (set), true);
763 : 207 : lra_update_insn_regno_info (insn);
764 : : }
765 : : }
766 : 44156 : continue;
767 : 44156 : }
768 : : }
769 : :
770 : : /* Update max ref width and hard reg usage. */
771 : 535471952 : for (reg = curr_id->regs; reg != NULL; reg = reg->next)
772 : : {
773 : 329117764 : int regno = reg->regno;
774 : :
775 : 329117764 : lra_update_biggest_mode (regno, reg->biggest_mode);
776 : 329117764 : if (HARD_REGISTER_NUM_P (regno))
777 : 89312426 : lra_hard_reg_usage[regno] += freq;
778 : : }
779 : :
780 : 206354188 : call_p = CALL_P (curr_insn);
781 : :
782 : : /* If we have a simple register copy and the source reg is live after
783 : : this instruction, then remove the source reg from the live set so
784 : : that it will not conflict with the destination reg. */
785 : 206354188 : rtx ignore_reg = non_conflicting_reg_copy_p (curr_insn);
786 : 206354188 : if (ignore_reg != NULL_RTX)
787 : : {
788 : 55335714 : int ignore_regno = REGNO (ignore_reg);
789 : 55335714 : if (HARD_REGISTER_NUM_P (ignore_regno)
790 : 55335714 : && TEST_HARD_REG_BIT (hard_regs_live, ignore_regno))
791 : 162754 : CLEAR_HARD_REG_BIT (hard_regs_live, ignore_regno);
792 : 55172960 : else if (!HARD_REGISTER_NUM_P (ignore_regno)
793 : 55172960 : && sparseset_bit_p (pseudos_live, ignore_regno))
794 : 11208892 : sparseset_clear_bit (pseudos_live, ignore_regno);
795 : : else
796 : : /* We don't need any special handling of the source reg if
797 : : it is dead after this instruction. */
798 : : ignore_reg = NULL_RTX;
799 : : }
800 : :
801 : 197003017 : src_regno = (set != NULL_RTX && REG_P (SET_SRC (set))
802 : 281249844 : ? REGNO (SET_SRC (set)) : -1);
803 : 197003017 : dst_regno = (set != NULL_RTX && REG_P (SET_DEST (set))
804 : 147275689 : ? REGNO (SET_DEST (set)) : -1);
805 : 206354188 : if (complete_info_p
806 : 205255111 : && src_regno >= 0 && dst_regno >= 0
807 : : /* Check that source regno does not conflict with
808 : : destination regno to exclude most impossible
809 : : preferences. */
810 : 261416545 : && (((!HARD_REGISTER_NUM_P (src_regno)
811 : 48510252 : && (! sparseset_bit_p (pseudos_live, src_regno)
812 : 9558 : || (!HARD_REGISTER_NUM_P (dst_regno)
813 : 55062357 : && lra_reg_val_equal_p (src_regno,
814 : : lra_reg_info[dst_regno].val,
815 : 0 : lra_reg_info[dst_regno].offset))))
816 : : || (HARD_REGISTER_NUM_P (src_regno)
817 : 6552105 : && ! TEST_HARD_REG_BIT (hard_regs_live, src_regno)))
818 : : /* It might be 'inheritance pseudo <- reload pseudo'. */
819 : 9571 : || (src_regno >= lra_constraint_new_regno_start
820 : 318 : && dst_regno >= lra_constraint_new_regno_start
821 : : /* Remember to skip special cases where src/dest regnos are
822 : : the same, e.g. insn SET pattern has matching constraints
823 : : like =r,0. */
824 : 0 : && src_regno != dst_regno)))
825 : : {
826 : 55052786 : int hard_regno = -1, regno = -1;
827 : :
828 : 55052786 : if (dst_regno >= lra_constraint_new_regno_start
829 : 14859435 : && src_regno >= lra_constraint_new_regno_start)
830 : : {
831 : : /* It might be still an original (non-reload) insn with
832 : : one unused output and a constraint requiring to use
833 : : the same reg for input/output operands. In this case
834 : : dst_regno and src_regno have the same value, we don't
835 : : need a misleading copy for this case. */
836 : 5520712 : if (dst_regno != src_regno)
837 : 5520712 : lra_create_copy (dst_regno, src_regno, freq);
838 : : }
839 : 49532074 : else if (dst_regno >= lra_constraint_new_regno_start)
840 : : {
841 : 9338723 : if (!HARD_REGISTER_NUM_P (hard_regno = src_regno))
842 : 9209142 : hard_regno = reg_renumber[src_regno];
843 : : regno = dst_regno;
844 : : }
845 : 40193351 : else if (src_regno >= lra_constraint_new_regno_start)
846 : : {
847 : 10136734 : if (!HARD_REGISTER_NUM_P (hard_regno = dst_regno))
848 : 8604673 : hard_regno = reg_renumber[dst_regno];
849 : : regno = src_regno;
850 : : }
851 : 55052786 : if (regno >= 0 && hard_regno >= 0)
852 : 11667479 : lra_setup_reload_pseudo_preferenced_hard_reg
853 : 11667479 : (regno, hard_regno, freq);
854 : : }
855 : :
856 : 206354188 : sparseset_clear (start_living);
857 : :
858 : : /* Mark each defined value as live. We need to do this for
859 : : unused values because they still conflict with quantities
860 : : that are live at the time of the definition. */
861 : 535471952 : for (reg = curr_id->regs; reg != NULL; reg = reg->next)
862 : 329117764 : if (reg->type != OP_IN)
863 : : {
864 : 143775287 : update_pseudo_point (reg->regno, curr_point, USE_POINT);
865 : 143775287 : mark_regno_live (reg->regno, reg->biggest_mode);
866 : : /* ??? Should be a no-op for unused registers. */
867 : 143775287 : check_pseudos_live_through_calls (reg->regno, last_call_abi);
868 : : }
869 : :
870 : 259294960 : for (reg = curr_static_id->hard_regs; reg != NULL; reg = reg->next)
871 : 52940772 : if (reg->type != OP_IN)
872 : 38294177 : make_hard_regno_live (reg->regno);
873 : :
874 : 206354188 : if (curr_id->arg_hard_regs != NULL)
875 : 30045282 : for (i = 0; (regno = curr_id->arg_hard_regs[i]) >= 0; i++)
876 : 21271153 : if (!HARD_REGISTER_NUM_P (regno))
877 : : /* It is a clobber. */
878 : 947787 : make_hard_regno_live (regno - FIRST_PSEUDO_REGISTER);
879 : :
880 : 206354188 : sparseset_copy (unused_set, start_living);
881 : :
882 : 206354188 : sparseset_clear (start_dying);
883 : :
884 : : /* See which defined values die here. */
885 : 535471952 : for (reg = curr_id->regs; reg != NULL; reg = reg->next)
886 : 329117764 : if (reg->type != OP_IN
887 : 615190737 : && ! reg_early_clobber_p (reg, n_alt) && ! reg->subreg_p)
888 : : {
889 : 142297686 : if (reg->type == OP_OUT)
890 : 123204650 : update_pseudo_point (reg->regno, curr_point, DEF_POINT);
891 : 142297686 : mark_regno_dead (reg->regno, reg->biggest_mode);
892 : : }
893 : :
894 : 259294960 : for (reg = curr_static_id->hard_regs; reg != NULL; reg = reg->next)
895 : 52940772 : if (reg->type != OP_IN
896 : 106471487 : && ! reg_early_clobber_p (reg, n_alt) && ! reg->subreg_p)
897 : 15236538 : make_hard_regno_dead (reg->regno);
898 : :
899 : 206354188 : if (curr_id->arg_hard_regs != NULL)
900 : 30045282 : for (i = 0; (regno = curr_id->arg_hard_regs[i]) >= 0; i++)
901 : 21271153 : if (!HARD_REGISTER_NUM_P (regno))
902 : : /* It is a clobber. */
903 : 947787 : make_hard_regno_dead (regno - FIRST_PSEUDO_REGISTER);
904 : :
905 : 206354188 : if (call_p)
906 : : {
907 : 11428079 : function_abi call_abi = insn_callee_abi (curr_insn);
908 : :
909 : 11428079 : if (last_call_abi != call_abi)
910 : 7516174 : EXECUTE_IF_SET_IN_SPARSESET (pseudos_live, j)
911 : 5416300 : check_pseudos_live_through_calls (j, last_call_abi);
912 : :
913 : 11428079 : last_call_abi = call_abi;
914 : :
915 : 11428079 : sparseset_ior (pseudos_live_through_calls,
916 : : pseudos_live_through_calls, pseudos_live);
917 : 11428079 : if (cfun->has_nonlocal_label
918 : 11428079 : || (!targetm.setjmp_preserves_nonvolatile_regs_p ()
919 : 11423903 : && (find_reg_note (curr_insn, REG_SETJMP, NULL_RTX)
920 : : != NULL_RTX)))
921 : 6504 : sparseset_ior (pseudos_live_through_setjumps,
922 : : pseudos_live_through_setjumps, pseudos_live);
923 : : }
924 : :
925 : : /* Increment the current program point if we must. */
926 : 206354188 : if (sparseset_contains_pseudos_p (unused_set)
927 : 206354188 : || sparseset_contains_pseudos_p (start_dying))
928 : 105194935 : next_program_point (curr_point, freq);
929 : :
930 : : /* If we removed the source reg from a simple register copy from the
931 : : live set above, then add it back now so we don't accidentally add
932 : : it to the start_living set below. */
933 : 206354188 : if (ignore_reg != NULL_RTX)
934 : : {
935 : 11371646 : int ignore_regno = REGNO (ignore_reg);
936 : 11371646 : if (HARD_REGISTER_NUM_P (ignore_regno))
937 : 162754 : SET_HARD_REG_BIT (hard_regs_live, ignore_regno);
938 : : else
939 : 11208892 : sparseset_set_bit (pseudos_live, ignore_regno);
940 : : }
941 : :
942 : 206354188 : sparseset_clear (start_living);
943 : :
944 : : /* Mark each used value as live. */
945 : 535471952 : for (reg = curr_id->regs; reg != NULL; reg = reg->next)
946 : 329117764 : if (reg->type != OP_OUT)
947 : : {
948 : 204564946 : if (reg->type == OP_IN)
949 : 185342477 : update_pseudo_point (reg->regno, curr_point, USE_POINT);
950 : 204564946 : mark_regno_live (reg->regno, reg->biggest_mode);
951 : 204564946 : check_pseudos_live_through_calls (reg->regno, last_call_abi);
952 : : }
953 : :
954 : 259294960 : for (reg = curr_static_id->hard_regs; reg != NULL; reg = reg->next)
955 : 52940772 : if (reg->type != OP_OUT)
956 : 15127272 : make_hard_regno_live (reg->regno);
957 : :
958 : 206354188 : if (curr_id->arg_hard_regs != NULL)
959 : : /* Make argument hard registers live. */
960 : 30045282 : for (i = 0; (regno = curr_id->arg_hard_regs[i]) >= 0; i++)
961 : 21271153 : if (HARD_REGISTER_NUM_P (regno))
962 : 20323366 : make_hard_regno_live (regno);
963 : :
964 : 206354188 : sparseset_and_compl (dead_set, start_living, start_dying);
965 : :
966 : 206354188 : sparseset_clear (start_dying);
967 : :
968 : : /* Mark early clobber outputs dead. */
969 : 535471952 : for (reg = curr_id->regs; reg != NULL; reg = reg->next)
970 : 329117764 : if (reg->type != OP_IN
971 : 473220745 : && reg_early_clobber_p (reg, n_alt) && ! reg->subreg_p)
972 : : {
973 : 327694 : if (reg->type == OP_OUT)
974 : 221420 : update_pseudo_point (reg->regno, curr_point, DEF_POINT);
975 : 327694 : mark_regno_dead (reg->regno, reg->biggest_mode);
976 : :
977 : : /* We're done processing inputs, so make sure early clobber
978 : : operands that are both inputs and outputs are still live. */
979 : 327694 : if (reg->type == OP_INOUT)
980 : 106274 : mark_regno_live (reg->regno, reg->biggest_mode);
981 : : }
982 : :
983 : 259294960 : for (reg = curr_static_id->hard_regs; reg != NULL; reg = reg->next)
984 : 52940772 : if (reg->type != OP_IN
985 : 114292588 : && reg_early_clobber_p (reg, n_alt) && ! reg->subreg_p)
986 : : {
987 : 23057639 : struct lra_insn_reg *reg2;
988 : :
989 : : /* We can have early clobbered non-operand hard reg and
990 : : the same hard reg as an insn input. Don't make hard
991 : : reg dead before the insns. */
992 : 46452945 : for (reg2 = curr_static_id->hard_regs; reg2 != NULL; reg2 = reg2->next)
993 : 23414331 : if (reg2->type != OP_OUT && reg2->regno == reg->regno)
994 : : break;
995 : 23057639 : if (reg2 != NULL)
996 : 19025 : continue;
997 : :
998 : : HARD_REG_SET clobbered_regset;
999 : 23038614 : CLEAR_HARD_REG_SET (clobbered_regset);
1000 : 23038614 : SET_HARD_REG_BIT (clobbered_regset, reg->regno);
1001 : :
1002 : 63745756 : for (reg2 = curr_id->regs; reg2 != NULL; reg2 = reg2->next)
1003 : 28969906 : if (reg2->type != OP_OUT && reg2->regno < FIRST_PSEUDO_REGISTER
1004 : 48803124 : && ira_hard_reg_set_intersection_p (reg2->regno,
1005 : 8087385 : reg2->biggest_mode,
1006 : : clobbered_regset))
1007 : : break;
1008 : 23038614 : if (reg2 == NULL)
1009 : : {
1010 : 23030017 : make_hard_regno_dead (reg->regno);
1011 : : }
1012 : : else
1013 : : {
1014 : 112890 : EXECUTE_IF_SET_IN_SPARSESET (pseudos_live, j)
1015 : 104293 : SET_HARD_REG_BIT (lra_reg_info[j].conflict_hard_regs,
1016 : : reg->regno);
1017 : : }
1018 : : }
1019 : :
1020 : : /* Increment the current program point if we must. */
1021 : 206354188 : if (sparseset_contains_pseudos_p (dead_set)
1022 : 206354188 : || sparseset_contains_pseudos_p (start_dying))
1023 : 81724373 : next_program_point (curr_point, freq);
1024 : :
1025 : : /* Update notes. */
1026 : 415031221 : for (link_loc = ®_NOTES (curr_insn); (link = *link_loc) != NULL_RTX;)
1027 : : {
1028 : 208677033 : if (REG_NOTE_KIND (link) != REG_DEAD
1029 : 86065378 : && REG_NOTE_KIND (link) != REG_UNUSED)
1030 : : ;
1031 : 148670507 : else if (REG_P (XEXP (link, 0)))
1032 : : {
1033 : 148670507 : rtx note_reg = XEXP (link, 0);
1034 : 148670507 : int note_regno = REGNO (note_reg);
1035 : :
1036 : 152058680 : if ((REG_NOTE_KIND (link) == REG_DEAD
1037 : 122611655 : && ! regnos_in_sparseset_p (dead_set, note_regno,
1038 : 122611655 : GET_MODE (note_reg)))
1039 : 269092728 : || (REG_NOTE_KIND (link) == REG_UNUSED
1040 : 26058852 : && ! regnos_in_sparseset_p (unused_set, note_regno,
1041 : 26058852 : GET_MODE (note_reg))))
1042 : : {
1043 : 3388173 : *link_loc = XEXP (link, 1);
1044 : 3388173 : continue;
1045 : : }
1046 : 145282334 : if (REG_NOTE_KIND (link) == REG_DEAD)
1047 : 120422221 : clear_sparseset_regnos (dead_set, note_regno,
1048 : 120422221 : GET_MODE (note_reg));
1049 : 24860113 : else if (REG_NOTE_KIND (link) == REG_UNUSED)
1050 : 24860113 : clear_sparseset_regnos (unused_set, note_regno,
1051 : 24860113 : GET_MODE (note_reg));
1052 : : }
1053 : 205288860 : link_loc = &XEXP (link, 1);
1054 : : }
1055 : 214736383 : EXECUTE_IF_SET_IN_SPARSESET (dead_set, j)
1056 : 8382195 : add_reg_note (curr_insn, REG_DEAD, regno_reg_rtx[j]);
1057 : 414633406 : EXECUTE_IF_SET_IN_SPARSESET (unused_set, j)
1058 : 1925030 : add_reg_note (curr_insn, REG_UNUSED, regno_reg_rtx[j]);
1059 : : }
1060 : :
1061 : 29950796 : if (bb_has_eh_pred (bb))
1062 : : /* Any pseudos that are currently live conflict with the eh_return
1063 : : data registers. For liveness purposes, these registers are set
1064 : : by artificial definitions at the start of the BB, so are not
1065 : : actually live on entry. */
1066 : 537298 : for (j = 0; ; ++j)
1067 : : {
1068 : 1611894 : unsigned int regno = EH_RETURN_DATA_REGNO (j);
1069 : :
1070 : 1074596 : if (regno == INVALID_REGNUM)
1071 : : break;
1072 : :
1073 : 1074596 : make_hard_regno_live (regno);
1074 : 1074596 : make_hard_regno_dead (regno);
1075 : 1074596 : }
1076 : :
1077 : : /* Pseudos can't go in stack regs at the start of a basic block that
1078 : : is reached by an abnormal edge. Likewise for registers that are at
1079 : : least partly call clobbered, because caller-save, fixup_abnormal_edges
1080 : : and possibly the table driven EH machinery are not quite ready to
1081 : : handle such pseudos live across such edges. */
1082 : 29950796 : if (bb_has_abnormal_pred (bb))
1083 : : {
1084 : : HARD_REG_SET clobbers;
1085 : :
1086 : 540577 : CLEAR_HARD_REG_SET (clobbers);
1087 : : #ifdef STACK_REGS
1088 : 1805190 : EXECUTE_IF_SET_IN_SPARSESET (pseudos_live, px)
1089 : 1264613 : lra_reg_info[px].no_stack_p = true;
1090 : 4865193 : for (px = FIRST_STACK_REG; px <= LAST_STACK_REG; px++)
1091 : 4324616 : SET_HARD_REG_BIT (clobbers, px);
1092 : : #endif
1093 : : /* No need to record conflicts for call clobbered regs if we
1094 : : have nonlocal labels around, as we don't ever try to
1095 : : allocate such regs in this case. */
1096 : 540577 : if (!cfun->has_nonlocal_label
1097 : 540577 : && has_abnormal_call_or_eh_pred_edge_p (bb))
1098 : 49967877 : for (px = 0; HARD_REGISTER_NUM_P (px); px++)
1099 : 49430588 : if (eh_edge_abi.clobbers_at_least_part_of_reg_p (px)
1100 : : #ifdef REAL_PIC_OFFSET_TABLE_REGNUM
1101 : : /* We should create a conflict of PIC pseudo with PIC
1102 : : hard reg as PIC hard reg can have a wrong value after
1103 : : jump described by the abnormal edge. In this case we
1104 : : cannot allocate PIC hard reg to PIC pseudo as PIC
1105 : : pseudo will also have a wrong value. */
1106 : 50007493 : || (px == REAL_PIC_OFFSET_TABLE_REGNUM
1107 : 537289 : && pic_offset_table_rtx != NULL_RTX
1108 : 25183 : && !HARD_REGISTER_P (pic_offset_table_rtx))
1109 : : #endif
1110 : : )
1111 : 44785000 : SET_HARD_REG_BIT (clobbers, px);
1112 : :
1113 : 540577 : clobbers &= ~hard_regs_live;
1114 : 50273661 : for (px = 0; HARD_REGISTER_NUM_P (px); px++)
1115 : 49733084 : if (TEST_HARD_REG_BIT (clobbers, px))
1116 : : {
1117 : 44811304 : make_hard_regno_live (px);
1118 : 44811304 : make_hard_regno_dead (px);
1119 : : }
1120 : : }
1121 : :
1122 : 29950796 : bool live_change_p = false;
1123 : : /* Check if bb border live info was changed. */
1124 : 29950796 : unsigned int live_pseudos_num = 0;
1125 : 406553987 : EXECUTE_IF_SET_IN_BITMAP (df_get_live_in (bb),
1126 : : FIRST_PSEUDO_REGISTER, j, bi)
1127 : : {
1128 : 376791817 : live_pseudos_num++;
1129 : 376791817 : if (! sparseset_bit_p (pseudos_live, j))
1130 : : {
1131 : 188626 : live_change_p = true;
1132 : 188626 : if (lra_dump_file != NULL)
1133 : 15 : fprintf (lra_dump_file,
1134 : : " r%d is removed as live at bb%d start\n", j, bb->index);
1135 : : break;
1136 : : }
1137 : : }
1138 : 15 : if (! live_change_p
1139 : 29762170 : && sparseset_cardinality (pseudos_live) != live_pseudos_num)
1140 : : {
1141 : 159579 : live_change_p = true;
1142 : 159579 : if (lra_dump_file != NULL)
1143 : 60 : EXECUTE_IF_SET_IN_SPARSESET (pseudos_live, j)
1144 : 22 : if (! bitmap_bit_p (df_get_live_in (bb), j))
1145 : 8 : fprintf (lra_dump_file,
1146 : : " r%d is added to live at bb%d start\n", j, bb->index);
1147 : : }
1148 : : /* See if we'll need an increment at the end of this basic block.
1149 : : An increment is needed if the PSEUDOS_LIVE set is not empty,
1150 : : to make sure the finish points are set up correctly. */
1151 : 29950796 : need_curr_point_incr = (sparseset_cardinality (pseudos_live) > 0);
1152 : :
1153 : 784352490 : EXECUTE_IF_SET_IN_SPARSESET (pseudos_live, i)
1154 : : {
1155 : 377200847 : update_pseudo_point (i, curr_point, DEF_POINT);
1156 : 377200847 : mark_pseudo_dead (i);
1157 : : }
1158 : :
1159 : 120302445 : EXECUTE_IF_SET_IN_BITMAP (df_get_live_in (bb), FIRST_PSEUDO_REGISTER, j, bi)
1160 : : {
1161 : 110696999 : if (sparseset_cardinality (pseudos_live_through_calls) == 0)
1162 : : break;
1163 : 90351649 : if (sparseset_bit_p (pseudos_live_through_calls, j))
1164 : 84569067 : check_pseudos_live_through_calls (j, last_call_abi);
1165 : : }
1166 : :
1167 : 2785424028 : for (i = 0; HARD_REGISTER_NUM_P (i); ++i)
1168 : : {
1169 : 2755473232 : if (!TEST_HARD_REG_BIT (hard_regs_live, i))
1170 : 2713843093 : continue;
1171 : :
1172 : 41630139 : if (!TEST_HARD_REG_BIT (hard_regs_spilled_into, i))
1173 : 41630139 : continue;
1174 : :
1175 : 0 : if (bitmap_bit_p (df_get_live_in (bb), i))
1176 : 0 : continue;
1177 : :
1178 : 0 : live_change_p = true;
1179 : 0 : if (lra_dump_file)
1180 : 0 : fprintf (lra_dump_file,
1181 : : " hard reg r%d is added to live at bb%d start\n", i,
1182 : : bb->index);
1183 : 0 : bitmap_set_bit (df_get_live_in (bb), i);
1184 : : }
1185 : :
1186 : 29950796 : if (need_curr_point_incr)
1187 : 23914250 : next_program_point (curr_point, freq);
1188 : :
1189 : 29950796 : return live_change_p;
1190 : : }
1191 : :
1192 : : /* Compress pseudo live ranges by removing program points where
1193 : : nothing happens. Complexity of many algorithms in LRA is linear
1194 : : function of program points number. To speed up the code we try to
1195 : : minimize the number of the program points here. */
1196 : : static void
1197 : 1512745 : remove_some_program_points_and_update_live_ranges (void)
1198 : : {
1199 : 1512745 : unsigned i;
1200 : 1512745 : int n, max_regno;
1201 : 1512745 : int *map;
1202 : 1512745 : lra_live_range_t r, prev_r, next_r;
1203 : 1512745 : sbitmap_iterator sbi;
1204 : 1512745 : bool born_p, dead_p, prev_born_p, prev_dead_p;
1205 : :
1206 : 1512745 : auto_sbitmap born (lra_live_max_point);
1207 : 1512745 : auto_sbitmap dead (lra_live_max_point);
1208 : 1512745 : bitmap_clear (born);
1209 : 1512745 : bitmap_clear (dead);
1210 : 1512745 : max_regno = max_reg_num ();
1211 : 162416468 : for (i = FIRST_PSEUDO_REGISTER; i < (unsigned) max_regno; i++)
1212 : : {
1213 : 265534179 : for (r = lra_reg_info[i].live_ranges; r != NULL; r = r->next)
1214 : : {
1215 : 104630456 : lra_assert (r->start <= r->finish);
1216 : 104630456 : bitmap_set_bit (born, r->start);
1217 : 104630456 : bitmap_set_bit (dead, r->finish);
1218 : : }
1219 : : }
1220 : 1512745 : auto_sbitmap born_or_dead (lra_live_max_point);
1221 : 1512745 : bitmap_ior (born_or_dead, born, dead);
1222 : 1512745 : map = XCNEWVEC (int, lra_live_max_point);
1223 : 1512745 : n = -1;
1224 : 1512745 : prev_born_p = prev_dead_p = false;
1225 : 184722983 : EXECUTE_IF_SET_IN_BITMAP (born_or_dead, 0, i, sbi)
1226 : : {
1227 : 181697493 : born_p = bitmap_bit_p (born, i);
1228 : 181697493 : dead_p = bitmap_bit_p (dead, i);
1229 : 181697493 : if ((prev_born_p && ! prev_dead_p && born_p && ! dead_p)
1230 : 167761972 : || (prev_dead_p && ! prev_born_p && dead_p && ! born_p))
1231 : : {
1232 : 39855817 : map[i] = n;
1233 : 39855817 : lra_point_freq[n] = MAX (lra_point_freq[n], lra_point_freq[i]);
1234 : : }
1235 : : else
1236 : : {
1237 : 141841676 : map[i] = ++n;
1238 : 141841676 : lra_point_freq[n] = lra_point_freq[i];
1239 : : }
1240 : 181697493 : prev_born_p = born_p;
1241 : 181697493 : prev_dead_p = dead_p;
1242 : : }
1243 : 1512745 : n++;
1244 : 1512745 : if (lra_dump_file != NULL)
1245 : 94 : fprintf (lra_dump_file, "Compressing live ranges: from %d to %d - %d%%\n",
1246 : : lra_live_max_point, n,
1247 : 94 : lra_live_max_point ? 100 * n / lra_live_max_point : 100);
1248 : 1512745 : if (n < lra_live_max_point)
1249 : : {
1250 : 1283748 : lra_live_max_point = n;
1251 : 159109185 : for (i = FIRST_PSEUDO_REGISTER; i < (unsigned) max_regno; i++)
1252 : : {
1253 : 157825437 : for (prev_r = NULL, r = lra_reg_info[i].live_ranges;
1254 : 261695739 : r != NULL;
1255 : : r = next_r)
1256 : : {
1257 : 103870302 : next_r = r->next;
1258 : 103870302 : r->start = map[r->start];
1259 : 103870302 : r->finish = map[r->finish];
1260 : 103870302 : if (prev_r == NULL || prev_r->start > r->finish + 1)
1261 : : {
1262 : 101832150 : prev_r = r;
1263 : 101832150 : continue;
1264 : : }
1265 : 2038152 : prev_r->start = r->start;
1266 : 2038152 : prev_r->next = next_r;
1267 : 2038152 : lra_live_range_pool.remove (r);
1268 : : }
1269 : : }
1270 : : }
1271 : 1512745 : free (map);
1272 : 1512745 : }
1273 : :
1274 : : /* Print live ranges R to file F. */
1275 : : void
1276 : 2302 : lra_print_live_range_list (FILE *f, lra_live_range_t r)
1277 : : {
1278 : 5118 : for (; r != NULL; r = r->next)
1279 : 2816 : fprintf (f, " [%d..%d]", r->start, r->finish);
1280 : 2302 : fprintf (f, "\n");
1281 : 2302 : }
1282 : :
1283 : : DEBUG_FUNCTION void
1284 : 0 : debug (lra_live_range &ref)
1285 : : {
1286 : 0 : lra_print_live_range_list (stderr, &ref);
1287 : 0 : }
1288 : :
1289 : : DEBUG_FUNCTION void
1290 : 0 : debug (lra_live_range *ptr)
1291 : : {
1292 : 0 : if (ptr)
1293 : 0 : debug (*ptr);
1294 : : else
1295 : 0 : fprintf (stderr, "<nil>\n");
1296 : 0 : }
1297 : :
1298 : : /* Print live ranges R to stderr. */
1299 : : void
1300 : 0 : lra_debug_live_range_list (lra_live_range_t r)
1301 : : {
1302 : 0 : lra_print_live_range_list (stderr, r);
1303 : 0 : }
1304 : :
1305 : : /* Print live ranges of pseudo REGNO to file F. */
1306 : : static void
1307 : 5538 : print_pseudo_live_ranges (FILE *f, int regno)
1308 : : {
1309 : 5538 : if (lra_reg_info[regno].live_ranges == NULL)
1310 : : return;
1311 : 2302 : fprintf (f, " r%d:", regno);
1312 : 2302 : lra_print_live_range_list (f, lra_reg_info[regno].live_ranges);
1313 : : }
1314 : :
1315 : : /* Print live ranges of pseudo REGNO to stderr. */
1316 : : void
1317 : 0 : lra_debug_pseudo_live_ranges (int regno)
1318 : : {
1319 : 0 : print_pseudo_live_ranges (stderr, regno);
1320 : 0 : }
1321 : :
1322 : : /* Print live ranges of all pseudos to file F. */
1323 : : static void
1324 : 188 : print_live_ranges (FILE *f)
1325 : : {
1326 : 188 : int i, max_regno;
1327 : :
1328 : 188 : max_regno = max_reg_num ();
1329 : 5914 : for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
1330 : 5538 : print_pseudo_live_ranges (f, i);
1331 : 188 : }
1332 : :
1333 : : /* Print live ranges of all pseudos to stderr. */
1334 : : void
1335 : 0 : lra_debug_live_ranges (void)
1336 : : {
1337 : 0 : print_live_ranges (stderr);
1338 : 0 : }
1339 : :
1340 : : /* Compress pseudo live ranges. */
1341 : : static void
1342 : 1512745 : compress_live_ranges (void)
1343 : : {
1344 : 1512745 : remove_some_program_points_and_update_live_ranges ();
1345 : 1512745 : if (lra_dump_file != NULL)
1346 : : {
1347 : 94 : fprintf (lra_dump_file, "Ranges after the compression:\n");
1348 : 94 : print_live_ranges (lra_dump_file);
1349 : : }
1350 : 1512745 : }
1351 : :
1352 : :
1353 : :
1354 : : /* The number of the current live range pass. */
1355 : : int lra_live_range_iter;
1356 : :
1357 : : /* The function creates live ranges only for memory pseudos (or for
1358 : : all ones if ALL_P), set up CONFLICT_HARD_REGS for the pseudos. It
1359 : : also does dead insn elimination if DEAD_INSN_P and global live
1360 : : analysis only for pseudos and only if the pseudo live info was
1361 : : changed on a BB border. Return TRUE if the live info was
1362 : : changed. */
1363 : : static bool
1364 : 1705879 : lra_create_live_ranges_1 (bool all_p, bool dead_insn_p)
1365 : : {
1366 : 1705879 : basic_block bb;
1367 : 1705879 : int i, hard_regno, max_regno = max_reg_num ();
1368 : 1705879 : int curr_point;
1369 : 1705879 : bool bb_live_change_p, have_referenced_pseudos = false;
1370 : :
1371 : 1705879 : timevar_push (TV_LRA_CREATE_LIVE_RANGES);
1372 : :
1373 : 1705879 : complete_info_p = all_p;
1374 : 1705879 : if (lra_dump_file != NULL)
1375 : 105 : fprintf (lra_dump_file,
1376 : : "\n********** Pseudo live ranges #%d: **********\n\n",
1377 : : ++lra_live_range_iter);
1378 : 1705879 : memset (lra_hard_reg_usage, 0, sizeof (lra_hard_reg_usage));
1379 : 321741230 : for (i = 0; i < max_regno; i++)
1380 : : {
1381 : 320035351 : lra_reg_info[i].live_ranges = NULL;
1382 : 320035351 : CLEAR_HARD_REG_SET (lra_reg_info[i].conflict_hard_regs);
1383 : 320035351 : lra_reg_info[i].preferred_hard_regno1 = -1;
1384 : 320035351 : lra_reg_info[i].preferred_hard_regno2 = -1;
1385 : 320035351 : lra_reg_info[i].preferred_hard_regno_profit1 = 0;
1386 : 320035351 : lra_reg_info[i].preferred_hard_regno_profit2 = 0;
1387 : : #ifdef STACK_REGS
1388 : 320035351 : lra_reg_info[i].no_stack_p = false;
1389 : : #endif
1390 : : /* The biggest mode is already set but its value might be to
1391 : : conservative because of recent transformation. Here in this
1392 : : file we recalculate it again as it costs practically
1393 : : nothing. */
1394 : 320035351 : if (!HARD_REGISTER_NUM_P (i) && regno_reg_rtx[i] != NULL_RTX)
1395 : 162269151 : lra_reg_info[i].biggest_mode = GET_MODE (regno_reg_rtx[i]);
1396 : : else
1397 : 157766200 : lra_reg_info[i].biggest_mode = VOIDmode;
1398 : 320035351 : if (!HARD_REGISTER_NUM_P (i)
1399 : 163094483 : && lra_reg_info[i].nrefs != 0)
1400 : : {
1401 : 83749151 : if ((hard_regno = reg_renumber[i]) >= 0)
1402 : 69359106 : lra_hard_reg_usage[hard_regno] += lra_reg_info[i].freq;
1403 : : have_referenced_pseudos = true;
1404 : : }
1405 : : }
1406 : 1705879 : lra_free_copies ();
1407 : :
1408 : : /* Under some circumstances, we can have functions without pseudo
1409 : : registers. For such functions, lra_live_max_point will be 0,
1410 : : see e.g. PR55604, and there's nothing more to do for us here. */
1411 : 1705879 : if (! have_referenced_pseudos)
1412 : : {
1413 : 193134 : timevar_pop (TV_LRA_CREATE_LIVE_RANGES);
1414 : 193134 : return false;
1415 : : }
1416 : :
1417 : 1512745 : pseudos_live = sparseset_alloc (max_regno);
1418 : 1512745 : pseudos_live_through_calls = sparseset_alloc (max_regno);
1419 : 1512745 : pseudos_live_through_setjumps = sparseset_alloc (max_regno);
1420 : 1512745 : start_living = sparseset_alloc (max_regno);
1421 : 1512745 : start_dying = sparseset_alloc (max_regno);
1422 : 1512745 : dead_set = sparseset_alloc (max_regno);
1423 : 1512745 : unused_set = sparseset_alloc (max_regno);
1424 : 1512745 : curr_point = 0;
1425 : 1512745 : unsigned new_length = get_max_uid () * 2;
1426 : 1512745 : point_freq_vec.truncate (0);
1427 : 1512745 : point_freq_vec.reserve_exact (new_length);
1428 : 1512745 : lra_point_freq = point_freq_vec.address ();
1429 : 1512745 : int *rpo = XNEWVEC (int, n_basic_blocks_for_fn (cfun));
1430 : 1512745 : int n = inverted_rev_post_order_compute (cfun, rpo);
1431 : 1512745 : lra_assert (n == n_basic_blocks_for_fn (cfun));
1432 : : bb_live_change_p = false;
1433 : 34489031 : for (i = 0; i < n; ++i)
1434 : : {
1435 : 32976286 : bb = BASIC_BLOCK_FOR_FN (cfun, rpo[i]);
1436 : 32976286 : if (bb == EXIT_BLOCK_PTR_FOR_FN (cfun) || bb
1437 : 31463541 : == ENTRY_BLOCK_PTR_FOR_FN (cfun))
1438 : 3025490 : continue;
1439 : 29950796 : if (process_bb_lives (bb, curr_point, dead_insn_p))
1440 : 32976286 : bb_live_change_p = true;
1441 : : }
1442 : 1512745 : free (rpo);
1443 : 1512745 : if (bb_live_change_p)
1444 : : {
1445 : : /* We need to clear pseudo live info as some pseudos can
1446 : : disappear, e.g. pseudos with used equivalences. */
1447 : 5683951 : FOR_EACH_BB_FN (bb, cfun)
1448 : : {
1449 : 5584153 : bitmap_clear_range (df_get_live_in (bb), FIRST_PSEUDO_REGISTER,
1450 : 5584153 : max_regno - FIRST_PSEUDO_REGISTER);
1451 : 5584153 : bitmap_clear_range (df_get_live_out (bb), FIRST_PSEUDO_REGISTER,
1452 : : max_regno - FIRST_PSEUDO_REGISTER);
1453 : : }
1454 : : /* As we did not change CFG since LRA start we can use
1455 : : DF-infrastructure solver to solve live data flow problem. */
1456 : 9281214 : for (int i = 0; HARD_REGISTER_NUM_P (i); ++i)
1457 : : {
1458 : 9181416 : if (TEST_HARD_REG_BIT (hard_regs_spilled_into, i))
1459 : 0 : bitmap_clear_bit (&all_hard_regs_bitmap, i);
1460 : : }
1461 : 99798 : df_simple_dataflow
1462 : 99798 : (DF_BACKWARD, NULL, live_con_fun_0, live_con_fun_n,
1463 : : live_trans_fun, &all_blocks,
1464 : : df_get_postorder (DF_BACKWARD), df_get_n_blocks (DF_BACKWARD));
1465 : 99798 : if (lra_dump_file != NULL)
1466 : : {
1467 : 8 : fprintf (lra_dump_file,
1468 : : "Global pseudo live data have been updated:\n");
1469 : 8 : basic_block bb;
1470 : 78 : FOR_EACH_BB_FN (bb, cfun)
1471 : : {
1472 : 70 : bb_data_t bb_info = get_bb_data (bb);
1473 : 70 : bitmap bb_livein = df_get_live_in (bb);
1474 : 70 : bitmap bb_liveout = df_get_live_out (bb);
1475 : :
1476 : 70 : fprintf (lra_dump_file, "\nBB %d:\n", bb->index);
1477 : 70 : lra_dump_bitmap_with_title (" gen:",
1478 : : &bb_info->gen_pseudos, bb->index);
1479 : 70 : lra_dump_bitmap_with_title (" killed:",
1480 : : &bb_info->killed_pseudos, bb->index);
1481 : 70 : lra_dump_bitmap_with_title (" livein:", bb_livein, bb->index);
1482 : 70 : lra_dump_bitmap_with_title (" liveout:", bb_liveout, bb->index);
1483 : : }
1484 : : }
1485 : : }
1486 : 1512745 : lra_live_max_point = curr_point;
1487 : 1512745 : if (lra_dump_file != NULL)
1488 : 94 : print_live_ranges (lra_dump_file);
1489 : : /* Clean up. */
1490 : 1512745 : sparseset_free (unused_set);
1491 : 1512745 : sparseset_free (dead_set);
1492 : 1512745 : sparseset_free (start_dying);
1493 : 1512745 : sparseset_free (start_living);
1494 : 1512745 : sparseset_free (pseudos_live_through_calls);
1495 : 1512745 : sparseset_free (pseudos_live_through_setjumps);
1496 : 1512745 : sparseset_free (pseudos_live);
1497 : 1512745 : compress_live_ranges ();
1498 : 1512745 : timevar_pop (TV_LRA_CREATE_LIVE_RANGES);
1499 : 1512745 : return bb_live_change_p;
1500 : : }
1501 : :
1502 : : /* The main entry function creates live-ranges and other live info
1503 : : necessary for the assignment sub-pass. It uses
1504 : : lra_creates_live_ranges_1 -- so read comments for the
1505 : : function. */
1506 : : void
1507 : 1606081 : lra_create_live_ranges (bool all_p, bool dead_insn_p)
1508 : : {
1509 : 1606081 : if (! lra_create_live_ranges_1 (all_p, dead_insn_p))
1510 : : return;
1511 : 99798 : if (lra_dump_file != NULL)
1512 : 8 : fprintf (lra_dump_file, "Live info was changed -- recalculate it\n");
1513 : : /* Live info was changed on a bb border. It means that some info,
1514 : : e.g. about conflict regs, calls crossed, and live ranges may be
1515 : : wrong. We need this info for allocation. So recalculate it
1516 : : again but without removing dead insns which can change live info
1517 : : again. Repetitive live range calculations are expensive therefore
1518 : : we stop here as we already have correct info although some
1519 : : improvement in rare cases could be possible on this sub-pass if
1520 : : we do dead insn elimination again (still the improvement may
1521 : : happen later). */
1522 : 99798 : lra_clear_live_ranges ();
1523 : 99798 : bool res = lra_create_live_ranges_1 (all_p, false);
1524 : 99798 : lra_assert (! res);
1525 : : }
1526 : :
1527 : : /* Finish all live ranges. */
1528 : : void
1529 : 1691413 : lra_clear_live_ranges (void)
1530 : : {
1531 : 1691413 : int i;
1532 : :
1533 : 310478381 : for (i = 0; i < max_reg_num (); i++)
1534 : 308786968 : free_live_range_list (lra_reg_info[i].live_ranges);
1535 : 1691413 : point_freq_vec.release ();
1536 : 1691413 : }
1537 : :
1538 : : /* Initialize live ranges data once per function. */
1539 : : void
1540 : 1431622 : lra_live_ranges_init (void)
1541 : : {
1542 : 1431622 : bitmap_initialize (&temp_bitmap, ®_obstack);
1543 : 1431622 : initiate_live_solver ();
1544 : 1431622 : }
1545 : :
1546 : : /* Finish live ranges data once per function. */
1547 : : void
1548 : 1431622 : lra_live_ranges_finish (void)
1549 : : {
1550 : 1431622 : finish_live_solver ();
1551 : 1431622 : bitmap_clear (&temp_bitmap);
1552 : 1431622 : lra_live_range_pool.release ();
1553 : 1431622 : }
|