]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/lra-lives.c
Rename struct in gcc/lra-lives.c
[thirdparty/gcc.git] / gcc / lra-lives.c
1 /* Build live ranges for pseudos.
2 Copyright (C) 2010-2014 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 "tm.h"
32 #include "hard-reg-set.h"
33 #include "rtl.h"
34 #include "tm_p.h"
35 #include "insn-config.h"
36 #include "recog.h"
37 #include "output.h"
38 #include "regs.h"
39 #include "hashtab.h"
40 #include "hash-set.h"
41 #include "vec.h"
42 #include "machmode.h"
43 #include "input.h"
44 #include "function.h"
45 #include "expr.h"
46 #include "predict.h"
47 #include "dominance.h"
48 #include "cfg.h"
49 #include "cfganal.h"
50 #include "basic-block.h"
51 #include "except.h"
52 #include "df.h"
53 #include "ira.h"
54 #include "sparseset.h"
55 #include "lra-int.h"
56
57 /* Program points are enumerated by numbers from range
58 0..LRA_LIVE_MAX_POINT-1. There are approximately two times more
59 program points than insns. Program points are places in the
60 program where liveness info can be changed. In most general case
61 (there are more complicated cases too) some program points
62 correspond to places where input operand dies and other ones
63 correspond to places where output operands are born. */
64 int lra_live_max_point;
65
66 /* Accumulated execution frequency of all references for each hard
67 register. */
68 int lra_hard_reg_usage[FIRST_PSEUDO_REGISTER];
69
70 /* A global flag whose true value says to build live ranges for all
71 pseudos, otherwise the live ranges only for pseudos got memory is
72 build. True value means also building copies and setting up hard
73 register preferences. The complete info is necessary only for the
74 assignment pass. The complete info is not needed for the
75 coalescing and spill passes. */
76 static bool complete_info_p;
77
78 /* Pseudos live at current point in the RTL scan. */
79 static sparseset pseudos_live;
80
81 /* Pseudos probably living through calls and setjumps. As setjump is
82 a call too, if a bit in PSEUDOS_LIVE_THROUGH_SETJUMPS is set up
83 then the corresponding bit in PSEUDOS_LIVE_THROUGH_CALLS is set up
84 too. These data are necessary for cases when only one subreg of a
85 multi-reg pseudo is set up after a call. So we decide it is
86 probably live when traversing bb backward. We are sure about
87 living when we see its usage or definition of the pseudo. */
88 static sparseset pseudos_live_through_calls;
89 static sparseset pseudos_live_through_setjumps;
90
91 /* Set of hard regs (except eliminable ones) currently live. */
92 static HARD_REG_SET hard_regs_live;
93
94 /* Set of pseudos and hard registers start living/dying in the current
95 insn. These sets are used to update REG_DEAD and REG_UNUSED notes
96 in the insn. */
97 static sparseset start_living, start_dying;
98
99 /* Set of pseudos and hard regs dead and unused in the current
100 insn. */
101 static sparseset unused_set, dead_set;
102
103 /* Pool for pseudo live ranges. */
104 static alloc_pool live_range_pool;
105
106 /* Free live range LR. */
107 static void
108 free_live_range (lra_live_range_t lr)
109 {
110 pool_free (live_range_pool, lr);
111 }
112
113 /* Free live range list LR. */
114 static void
115 free_live_range_list (lra_live_range_t lr)
116 {
117 lra_live_range_t next;
118
119 while (lr != NULL)
120 {
121 next = lr->next;
122 free_live_range (lr);
123 lr = next;
124 }
125 }
126
127 /* Create and return pseudo live range with given attributes. */
128 static lra_live_range_t
129 create_live_range (int regno, int start, int finish, lra_live_range_t next)
130 {
131 lra_live_range_t p;
132
133 p = (lra_live_range_t) pool_alloc (live_range_pool);
134 p->regno = regno;
135 p->start = start;
136 p->finish = finish;
137 p->next = next;
138 return p;
139 }
140
141 /* Copy live range R and return the result. */
142 static lra_live_range_t
143 copy_live_range (lra_live_range_t r)
144 {
145 lra_live_range_t p;
146
147 p = (lra_live_range_t) pool_alloc (live_range_pool);
148 *p = *r;
149 return p;
150 }
151
152 /* Copy live range list given by its head R and return the result. */
153 lra_live_range_t
154 lra_copy_live_range_list (lra_live_range_t r)
155 {
156 lra_live_range_t p, first, *chain;
157
158 first = NULL;
159 for (chain = &first; r != NULL; r = r->next)
160 {
161 p = copy_live_range (r);
162 *chain = p;
163 chain = &p->next;
164 }
165 return first;
166 }
167
168 /* Merge *non-intersected* ranges R1 and R2 and returns the result.
169 The function maintains the order of ranges and tries to minimize
170 size of the result range list. Ranges R1 and R2 may not be used
171 after the call. */
172 lra_live_range_t
173 lra_merge_live_ranges (lra_live_range_t r1, lra_live_range_t r2)
174 {
175 lra_live_range_t first, last, temp;
176
177 if (r1 == NULL)
178 return r2;
179 if (r2 == NULL)
180 return r1;
181 for (first = last = NULL; r1 != NULL && r2 != NULL;)
182 {
183 if (r1->start < r2->start)
184 {
185 temp = r1;
186 r1 = r2;
187 r2 = temp;
188 }
189 if (r1->start == r2->finish + 1)
190 {
191 /* Joint ranges: merge r1 and r2 into r1. */
192 r1->start = r2->start;
193 temp = r2;
194 r2 = r2->next;
195 pool_free (live_range_pool, temp);
196 }
197 else
198 {
199 gcc_assert (r2->finish + 1 < r1->start);
200 /* Add r1 to the result. */
201 if (first == NULL)
202 first = last = r1;
203 else
204 {
205 last->next = r1;
206 last = r1;
207 }
208 r1 = r1->next;
209 }
210 }
211 if (r1 != NULL)
212 {
213 if (first == NULL)
214 first = r1;
215 else
216 last->next = r1;
217 }
218 else
219 {
220 lra_assert (r2 != NULL);
221 if (first == NULL)
222 first = r2;
223 else
224 last->next = r2;
225 }
226 return first;
227 }
228
229 /* Return TRUE if live ranges R1 and R2 intersect. */
230 bool
231 lra_intersected_live_ranges_p (lra_live_range_t r1, lra_live_range_t r2)
232 {
233 /* Remember the live ranges are always kept ordered. */
234 while (r1 != NULL && r2 != NULL)
235 {
236 if (r1->start > r2->finish)
237 r1 = r1->next;
238 else if (r2->start > r1->finish)
239 r2 = r2->next;
240 else
241 return true;
242 }
243 return false;
244 }
245
246 /* The function processing birth of hard register REGNO. It updates
247 living hard regs, conflict hard regs for living pseudos, and
248 START_LIVING. */
249 static void
250 make_hard_regno_born (int regno)
251 {
252 unsigned int i;
253
254 lra_assert (regno < FIRST_PSEUDO_REGISTER);
255 if (TEST_HARD_REG_BIT (hard_regs_live, regno))
256 return;
257 SET_HARD_REG_BIT (hard_regs_live, regno);
258 sparseset_set_bit (start_living, regno);
259 EXECUTE_IF_SET_IN_SPARSESET (pseudos_live, i)
260 SET_HARD_REG_BIT (lra_reg_info[i].conflict_hard_regs, regno);
261 }
262
263 /* Process the death of hard register REGNO. This updates
264 hard_regs_live and START_DYING. */
265 static void
266 make_hard_regno_dead (int regno)
267 {
268 lra_assert (regno < FIRST_PSEUDO_REGISTER);
269 if (! TEST_HARD_REG_BIT (hard_regs_live, regno))
270 return;
271 sparseset_set_bit (start_dying, regno);
272 CLEAR_HARD_REG_BIT (hard_regs_live, regno);
273 }
274
275 /* Mark pseudo REGNO as living at program point POINT, update conflicting
276 hard registers of the pseudo and START_LIVING, and start a new live
277 range for the pseudo corresponding to REGNO if it is necessary. */
278 static void
279 mark_pseudo_live (int regno, int point)
280 {
281 lra_live_range_t p;
282
283 lra_assert (regno >= FIRST_PSEUDO_REGISTER);
284 lra_assert (! sparseset_bit_p (pseudos_live, regno));
285 sparseset_set_bit (pseudos_live, regno);
286 IOR_HARD_REG_SET (lra_reg_info[regno].conflict_hard_regs, hard_regs_live);
287
288 if ((complete_info_p || lra_get_regno_hard_regno (regno) < 0)
289 && ((p = lra_reg_info[regno].live_ranges) == NULL
290 || (p->finish != point && p->finish + 1 != point)))
291 lra_reg_info[regno].live_ranges
292 = create_live_range (regno, point, -1, p);
293 sparseset_set_bit (start_living, regno);
294 }
295
296 /* Mark pseudo REGNO as not living at program point POINT and update
297 START_DYING.
298 This finishes the current live range for the pseudo corresponding
299 to REGNO. */
300 static void
301 mark_pseudo_dead (int regno, int point)
302 {
303 lra_live_range_t p;
304
305 lra_assert (regno >= FIRST_PSEUDO_REGISTER);
306 lra_assert (sparseset_bit_p (pseudos_live, regno));
307 sparseset_clear_bit (pseudos_live, regno);
308 sparseset_set_bit (start_dying, regno);
309 if (complete_info_p || lra_get_regno_hard_regno (regno) < 0)
310 {
311 p = lra_reg_info[regno].live_ranges;
312 lra_assert (p != NULL);
313 p->finish = point;
314 }
315 }
316
317 /* The corresponding bitmaps of BB currently being processed. */
318 static bitmap bb_killed_pseudos, bb_gen_pseudos;
319
320 /* Mark register REGNO (pseudo or hard register) in MODE as live at
321 program point POINT. Update BB_GEN_PSEUDOS if LOCAL_SETS_P.
322 Return TRUE if the liveness tracking sets were modified, or FALSE
323 if nothing changed. */
324 static bool
325 mark_regno_live (int regno, machine_mode mode, int point, bool local_sets_p)
326 {
327 int last;
328 bool changed = false;
329
330 if (regno < FIRST_PSEUDO_REGISTER)
331 {
332 for (last = regno + hard_regno_nregs[regno][mode];
333 regno < last;
334 regno++)
335 make_hard_regno_born (regno);
336 }
337 else
338 {
339 if (! sparseset_bit_p (pseudos_live, regno))
340 {
341 mark_pseudo_live (regno, point);
342 changed = true;
343 }
344 if (local_sets_p)
345 bitmap_set_bit (bb_gen_pseudos, regno);
346 }
347 return changed;
348 }
349
350
351 /* Mark register REGNO in MODE as dead at program point POINT. Update
352 BB_GEN_PSEUDOS and BB_KILLED_PSEUDOS if LOCAL_SETS_P. Return TRUE
353 if the liveness tracking sets were modified, or FALSE if nothing
354 changed. */
355 static bool
356 mark_regno_dead (int regno, machine_mode mode, int point, bool local_sets_p)
357 {
358 int last;
359 bool changed = false;
360
361 if (regno < FIRST_PSEUDO_REGISTER)
362 {
363 for (last = regno + hard_regno_nregs[regno][mode];
364 regno < last;
365 regno++)
366 make_hard_regno_dead (regno);
367 }
368 else
369 {
370 if (sparseset_bit_p (pseudos_live, regno))
371 {
372 mark_pseudo_dead (regno, point);
373 changed = true;
374 }
375 if (local_sets_p)
376 {
377 bitmap_clear_bit (bb_gen_pseudos, regno);
378 bitmap_set_bit (bb_killed_pseudos, regno);
379 }
380 }
381 return changed;
382 }
383
384 \f
385
386 /* This page contains code for making global live analysis of pseudos.
387 The code works only when pseudo live info is changed on a BB
388 border. That might be a consequence of some global transformations
389 in LRA, e.g. PIC pseudo reuse or rematerialization. */
390
391 /* Structure describing local BB data used for pseudo
392 live-analysis. */
393 struct bb_data_pseudos
394 {
395 /* Basic block about which the below data are. */
396 basic_block bb;
397 bitmap_head killed_pseudos; /* pseudos killed in the BB. */
398 bitmap_head gen_pseudos; /* pseudos generated in the BB. */
399 };
400
401 /* Array for all BB data. Indexed by the corresponding BB index. */
402 typedef struct bb_data_pseudos *bb_data_t;
403
404 /* All basic block data are referred through the following array. */
405 static bb_data_t bb_data;
406
407 /* Two small functions for access to the bb data. */
408 static inline bb_data_t
409 get_bb_data (basic_block bb)
410 {
411 return &bb_data[(bb)->index];
412 }
413
414 static inline bb_data_t
415 get_bb_data_by_index (int index)
416 {
417 return &bb_data[index];
418 }
419
420 /* Bitmap with all hard regs. */
421 static bitmap_head all_hard_regs_bitmap;
422
423 /* Bitmap used for holding intermediate bitmap operation results. */
424 static bitmap_head temp_bitmap;
425
426 /* The transfer function used by the DF equation solver to propagate
427 live info through block with BB_INDEX according to the following
428 equation:
429
430 bb.livein = (bb.liveout - bb.kill) OR bb.gen
431 */
432 static bool
433 live_trans_fun (int bb_index)
434 {
435 basic_block bb = get_bb_data_by_index (bb_index)->bb;
436 bitmap bb_liveout = df_get_live_out (bb);
437 bitmap bb_livein = df_get_live_in (bb);
438 bb_data_t bb_info = get_bb_data (bb);
439
440 bitmap_and_compl (&temp_bitmap, bb_liveout, &all_hard_regs_bitmap);
441 return bitmap_ior_and_compl (bb_livein, &bb_info->gen_pseudos,
442 &temp_bitmap, &bb_info->killed_pseudos);
443 }
444
445 /* The confluence function used by the DF equation solver to set up
446 live info for a block BB without predecessor. */
447 static void
448 live_con_fun_0 (basic_block bb)
449 {
450 bitmap_and_into (df_get_live_out (bb), &all_hard_regs_bitmap);
451 }
452
453 /* The confluence function used by the DF equation solver to propagate
454 live info from successor to predecessor on edge E according to the
455 following equation:
456
457 bb.liveout = 0 for entry block | OR (livein of successors)
458 */
459 static bool
460 live_con_fun_n (edge e)
461 {
462 basic_block bb = e->src;
463 basic_block dest = e->dest;
464 bitmap bb_liveout = df_get_live_out (bb);
465 bitmap dest_livein = df_get_live_in (dest);
466
467 return bitmap_ior_and_compl_into (bb_liveout,
468 dest_livein, &all_hard_regs_bitmap);
469 }
470
471 /* Indexes of all function blocks. */
472 static bitmap_head all_blocks;
473
474 /* Allocate and initialize data needed for global pseudo live
475 analysis. */
476 static void
477 initiate_live_solver (void)
478 {
479 bitmap_initialize (&temp_bitmap, &reg_obstack);
480 bitmap_initialize (&all_hard_regs_bitmap, &reg_obstack);
481 bitmap_set_range (&all_hard_regs_bitmap, 0, FIRST_PSEUDO_REGISTER);
482 bb_data = XNEWVEC (struct bb_data_pseudos, last_basic_block_for_fn (cfun));
483 bitmap_initialize (&all_blocks, &reg_obstack);
484
485 basic_block bb;
486 FOR_ALL_BB_FN (bb, cfun)
487 {
488 bb_data_t bb_info = get_bb_data (bb);
489 bb_info->bb = bb;
490 bitmap_initialize (&bb_info->killed_pseudos, &reg_obstack);
491 bitmap_initialize (&bb_info->gen_pseudos, &reg_obstack);
492 bitmap_set_bit (&all_blocks, bb->index);
493 }
494 }
495
496 /* Free all data needed for global pseudo live analysis. */
497 static void
498 finish_live_solver (void)
499 {
500 basic_block bb;
501
502 bitmap_clear (&all_blocks);
503 FOR_ALL_BB_FN (bb, cfun)
504 {
505 bb_data_t bb_info = get_bb_data (bb);
506 bitmap_clear (&bb_info->killed_pseudos);
507 bitmap_clear (&bb_info->gen_pseudos);
508 }
509 free (bb_data);
510 bitmap_clear (&all_hard_regs_bitmap);
511 bitmap_clear (&temp_bitmap);
512 }
513
514 \f
515
516 /* Insn currently scanned. */
517 static rtx_insn *curr_insn;
518 /* The insn data. */
519 static lra_insn_recog_data_t curr_id;
520 /* The insn static data. */
521 static struct lra_static_insn_data *curr_static_id;
522
523 /* Return true when one of the predecessor edges of BB is marked with
524 EDGE_ABNORMAL_CALL or EDGE_EH. */
525 static bool
526 bb_has_abnormal_call_pred (basic_block bb)
527 {
528 edge e;
529 edge_iterator ei;
530
531 FOR_EACH_EDGE (e, ei, bb->preds)
532 {
533 if (e->flags & (EDGE_ABNORMAL_CALL | EDGE_EH))
534 return true;
535 }
536 return false;
537 }
538
539 /* Vec containing execution frequencies of program points. */
540 static vec<int> point_freq_vec;
541
542 /* The start of the above vector elements. */
543 int *lra_point_freq;
544
545 /* Increment the current program point POINT to the next point which has
546 execution frequency FREQ. */
547 static void
548 next_program_point (int &point, int freq)
549 {
550 point_freq_vec.safe_push (freq);
551 lra_point_freq = point_freq_vec.address ();
552 point++;
553 }
554
555 /* Update the preference of HARD_REGNO for pseudo REGNO by PROFIT. */
556 void
557 lra_setup_reload_pseudo_preferenced_hard_reg (int regno,
558 int hard_regno, int profit)
559 {
560 lra_assert (regno >= lra_constraint_new_regno_start);
561 if (lra_reg_info[regno].preferred_hard_regno1 == hard_regno)
562 lra_reg_info[regno].preferred_hard_regno_profit1 += profit;
563 else if (lra_reg_info[regno].preferred_hard_regno2 == hard_regno)
564 lra_reg_info[regno].preferred_hard_regno_profit2 += profit;
565 else if (lra_reg_info[regno].preferred_hard_regno1 < 0)
566 {
567 lra_reg_info[regno].preferred_hard_regno1 = hard_regno;
568 lra_reg_info[regno].preferred_hard_regno_profit1 = profit;
569 }
570 else if (lra_reg_info[regno].preferred_hard_regno2 < 0
571 || profit > lra_reg_info[regno].preferred_hard_regno_profit2)
572 {
573 lra_reg_info[regno].preferred_hard_regno2 = hard_regno;
574 lra_reg_info[regno].preferred_hard_regno_profit2 = profit;
575 }
576 else
577 return;
578 /* Keep the 1st hard regno as more profitable. */
579 if (lra_reg_info[regno].preferred_hard_regno1 >= 0
580 && lra_reg_info[regno].preferred_hard_regno2 >= 0
581 && (lra_reg_info[regno].preferred_hard_regno_profit2
582 > lra_reg_info[regno].preferred_hard_regno_profit1))
583 {
584 int temp;
585
586 temp = lra_reg_info[regno].preferred_hard_regno1;
587 lra_reg_info[regno].preferred_hard_regno1
588 = lra_reg_info[regno].preferred_hard_regno2;
589 lra_reg_info[regno].preferred_hard_regno2 = temp;
590 temp = lra_reg_info[regno].preferred_hard_regno_profit1;
591 lra_reg_info[regno].preferred_hard_regno_profit1
592 = lra_reg_info[regno].preferred_hard_regno_profit2;
593 lra_reg_info[regno].preferred_hard_regno_profit2 = temp;
594 }
595 if (lra_dump_file != NULL)
596 {
597 if ((hard_regno = lra_reg_info[regno].preferred_hard_regno1) >= 0)
598 fprintf (lra_dump_file,
599 " Hard reg %d is preferable by r%d with profit %d\n",
600 hard_regno, regno,
601 lra_reg_info[regno].preferred_hard_regno_profit1);
602 if ((hard_regno = lra_reg_info[regno].preferred_hard_regno2) >= 0)
603 fprintf (lra_dump_file,
604 " Hard reg %d is preferable by r%d with profit %d\n",
605 hard_regno, regno,
606 lra_reg_info[regno].preferred_hard_regno_profit2);
607 }
608 }
609
610 /* Check that REGNO living through calls and setjumps, set up conflict
611 regs, and clear corresponding bits in PSEUDOS_LIVE_THROUGH_CALLS and
612 PSEUDOS_LIVE_THROUGH_SETJUMPS. */
613 static inline void
614 check_pseudos_live_through_calls (int regno)
615 {
616 int hr;
617
618 if (! sparseset_bit_p (pseudos_live_through_calls, regno))
619 return;
620 sparseset_clear_bit (pseudos_live_through_calls, regno);
621 IOR_HARD_REG_SET (lra_reg_info[regno].conflict_hard_regs,
622 call_used_reg_set);
623
624 for (hr = 0; hr < FIRST_PSEUDO_REGISTER; hr++)
625 if (HARD_REGNO_CALL_PART_CLOBBERED (hr, PSEUDO_REGNO_MODE (regno)))
626 SET_HARD_REG_BIT (lra_reg_info[regno].conflict_hard_regs, hr);
627 #ifdef ENABLE_CHECKING
628 lra_reg_info[regno].call_p = true;
629 #endif
630 if (! sparseset_bit_p (pseudos_live_through_setjumps, regno))
631 return;
632 sparseset_clear_bit (pseudos_live_through_setjumps, regno);
633 /* Don't allocate pseudos that cross setjmps or any call, if this
634 function receives a nonlocal goto. */
635 SET_HARD_REG_SET (lra_reg_info[regno].conflict_hard_regs);
636 }
637
638 /* Process insns of the basic block BB to update pseudo live ranges,
639 pseudo hard register conflicts, and insn notes. We do it on
640 backward scan of BB insns. CURR_POINT is the program point where
641 BB ends. The function updates this counter and returns in
642 CURR_POINT the program point where BB starts. The function also
643 can delete the dead insns. It returns true if pseudo live info was
644 changed at the BB start. */
645 static bool
646 process_bb_lives (basic_block bb, int &curr_point)
647 {
648 int i, regno, freq;
649 unsigned int j;
650 bitmap_iterator bi;
651 bitmap reg_live_out;
652 unsigned int px;
653 rtx_insn *next;
654 rtx link, *link_loc;
655 bool need_curr_point_incr;
656
657 reg_live_out = df_get_live_out (bb);
658 sparseset_clear (pseudos_live);
659 sparseset_clear (pseudos_live_through_calls);
660 sparseset_clear (pseudos_live_through_setjumps);
661 REG_SET_TO_HARD_REG_SET (hard_regs_live, reg_live_out);
662 AND_COMPL_HARD_REG_SET (hard_regs_live, eliminable_regset);
663 EXECUTE_IF_SET_IN_BITMAP (reg_live_out, FIRST_PSEUDO_REGISTER, j, bi)
664 mark_pseudo_live (j, curr_point);
665
666 bb_gen_pseudos = &get_bb_data (bb)->gen_pseudos;
667 bb_killed_pseudos = &get_bb_data (bb)->killed_pseudos;
668 bitmap_clear (bb_gen_pseudos);
669 bitmap_clear (bb_killed_pseudos);
670
671 freq = REG_FREQ_FROM_BB (bb);
672
673 if (lra_dump_file != NULL)
674 fprintf (lra_dump_file, " BB %d\n", bb->index);
675
676 /* Scan the code of this basic block, noting which pseudos and hard
677 regs are born or die.
678
679 Note that this loop treats uninitialized values as live until the
680 beginning of the block. For example, if an instruction uses
681 (reg:DI foo), and only (subreg:SI (reg:DI foo) 0) is ever set,
682 FOO will remain live until the beginning of the block. Likewise
683 if FOO is not set at all. This is unnecessarily pessimistic, but
684 it probably doesn't matter much in practice. */
685 FOR_BB_INSNS_REVERSE_SAFE (bb, curr_insn, next)
686 {
687 bool call_p;
688 int dst_regno, src_regno;
689 rtx set;
690 struct lra_insn_reg *reg;
691
692 if (!NONDEBUG_INSN_P (curr_insn))
693 continue;
694
695 curr_id = lra_get_insn_recog_data (curr_insn);
696 curr_static_id = curr_id->insn_static_data;
697 if (lra_dump_file != NULL)
698 fprintf (lra_dump_file, " Insn %u: point = %d\n",
699 INSN_UID (curr_insn), curr_point);
700
701 set = single_set (curr_insn);
702
703 if (set != NULL_RTX
704 && REG_P (SET_DEST (set)) && REGNO (SET_DEST (set)) >= FIRST_PSEUDO_REGISTER
705 && find_reg_note (curr_insn, REG_EH_REGION, NULL_RTX) == NULL_RTX
706 && ! may_trap_p (PATTERN (curr_insn))
707 /* Don't do premature remove of pic offset pseudo as we can
708 start to use it after some reload generation. */
709 && (pic_offset_table_rtx == NULL_RTX
710 || pic_offset_table_rtx != SET_DEST (set)))
711 {
712 bool dead_insn_p = true;
713
714 for (reg = curr_id->regs; reg != NULL; reg = reg->next)
715 if (reg->type != OP_IN && sparseset_bit_p (pseudos_live, reg->regno))
716 {
717 dead_insn_p = false;
718 break;
719 }
720 for (reg = curr_static_id->hard_regs; reg != NULL; reg = reg->next)
721 if (reg->type != OP_IN)
722 {
723 dead_insn_p = false;
724 break;
725 }
726 if (dead_insn_p && ! volatile_refs_p (PATTERN (curr_insn)))
727 {
728 dst_regno = REGNO (SET_DEST (set));
729 if (lra_dump_file != NULL)
730 fprintf (lra_dump_file, " Deleting dead insn %u\n",
731 INSN_UID (curr_insn));
732 lra_set_insn_deleted (curr_insn);
733 if (lra_reg_info[dst_regno].nrefs == 0)
734 {
735 /* There might be some debug insns with the pseudo. */
736 unsigned int uid;
737 rtx_insn *insn;
738
739 EXECUTE_IF_SET_IN_BITMAP
740 (&lra_reg_info[dst_regno].insn_bitmap, 0, uid, bi)
741 {
742 insn = lra_insn_recog_data[uid]->insn;
743 lra_substitute_pseudo_within_insn (insn, dst_regno,
744 SET_SRC (set));
745 lra_update_insn_regno_info (insn);
746 }
747 }
748 continue;
749 }
750 }
751
752 /* Update max ref width and hard reg usage. */
753 for (reg = curr_id->regs; reg != NULL; reg = reg->next)
754 if (reg->regno >= FIRST_PSEUDO_REGISTER
755 && (GET_MODE_SIZE (reg->biggest_mode)
756 > GET_MODE_SIZE (lra_reg_info[reg->regno].biggest_mode)))
757 lra_reg_info[reg->regno].biggest_mode = reg->biggest_mode;
758 else if (reg->regno < FIRST_PSEUDO_REGISTER)
759 lra_hard_reg_usage[reg->regno] += freq;
760
761 call_p = CALL_P (curr_insn);
762 if (complete_info_p
763 && set != NULL_RTX
764 && REG_P (SET_DEST (set)) && REG_P (SET_SRC (set))
765 /* Check that source regno does not conflict with
766 destination regno to exclude most impossible
767 preferences. */
768 && ((((src_regno = REGNO (SET_SRC (set))) >= FIRST_PSEUDO_REGISTER
769 && ! sparseset_bit_p (pseudos_live, src_regno))
770 || (src_regno < FIRST_PSEUDO_REGISTER
771 && ! TEST_HARD_REG_BIT (hard_regs_live, src_regno)))
772 /* It might be 'inheritance pseudo <- reload pseudo'. */
773 || (src_regno >= lra_constraint_new_regno_start
774 && ((int) REGNO (SET_DEST (set))
775 >= lra_constraint_new_regno_start)
776 /* Remember to skip special cases where src/dest regnos are
777 the same, e.g. insn SET pattern has matching constraints
778 like =r,0. */
779 && src_regno != (int) REGNO (SET_DEST (set)))))
780 {
781 int hard_regno = -1, regno = -1;
782
783 dst_regno = REGNO (SET_DEST (set));
784 if (dst_regno >= lra_constraint_new_regno_start
785 && src_regno >= lra_constraint_new_regno_start)
786 lra_create_copy (dst_regno, src_regno, freq);
787 else if (dst_regno >= lra_constraint_new_regno_start)
788 {
789 if ((hard_regno = src_regno) >= FIRST_PSEUDO_REGISTER)
790 hard_regno = reg_renumber[src_regno];
791 regno = dst_regno;
792 }
793 else if (src_regno >= lra_constraint_new_regno_start)
794 {
795 if ((hard_regno = dst_regno) >= FIRST_PSEUDO_REGISTER)
796 hard_regno = reg_renumber[dst_regno];
797 regno = src_regno;
798 }
799 if (regno >= 0 && hard_regno >= 0)
800 lra_setup_reload_pseudo_preferenced_hard_reg
801 (regno, hard_regno, freq);
802 }
803
804 sparseset_clear (start_living);
805
806 /* Try to avoid unnecessary program point increments, this saves
807 a lot of time in remove_some_program_points_and_update_live_ranges.
808 We only need an increment if something becomes live or dies at this
809 program point. */
810 need_curr_point_incr = false;
811
812 /* Mark each defined value as live. We need to do this for
813 unused values because they still conflict with quantities
814 that are live at the time of the definition. */
815 for (reg = curr_id->regs; reg != NULL; reg = reg->next)
816 if (reg->type != OP_IN)
817 {
818 need_curr_point_incr |= mark_regno_live (reg->regno,
819 reg->biggest_mode,
820 curr_point, true);
821 check_pseudos_live_through_calls (reg->regno);
822 }
823
824 for (reg = curr_static_id->hard_regs; reg != NULL; reg = reg->next)
825 if (reg->type != OP_IN)
826 make_hard_regno_born (reg->regno);
827
828 sparseset_copy (unused_set, start_living);
829
830 sparseset_clear (start_dying);
831
832 /* See which defined values die here. */
833 for (reg = curr_id->regs; reg != NULL; reg = reg->next)
834 if (reg->type == OP_OUT && ! reg->early_clobber && ! reg->subreg_p)
835 need_curr_point_incr |= mark_regno_dead (reg->regno,
836 reg->biggest_mode,
837 curr_point, true);
838
839 for (reg = curr_static_id->hard_regs; reg != NULL; reg = reg->next)
840 if (reg->type == OP_OUT && ! reg->early_clobber && ! reg->subreg_p)
841 make_hard_regno_dead (reg->regno);
842
843 if (call_p)
844 {
845 if (flag_use_caller_save)
846 {
847 HARD_REG_SET this_call_used_reg_set;
848 get_call_reg_set_usage (curr_insn, &this_call_used_reg_set,
849 call_used_reg_set);
850
851 EXECUTE_IF_SET_IN_SPARSESET (pseudos_live, j)
852 IOR_HARD_REG_SET (lra_reg_info[j].actual_call_used_reg_set,
853 this_call_used_reg_set);
854 }
855
856 sparseset_ior (pseudos_live_through_calls,
857 pseudos_live_through_calls, pseudos_live);
858 if (cfun->has_nonlocal_label
859 || find_reg_note (curr_insn, REG_SETJMP,
860 NULL_RTX) != NULL_RTX)
861 sparseset_ior (pseudos_live_through_setjumps,
862 pseudos_live_through_setjumps, pseudos_live);
863 }
864
865 /* Increment the current program point if we must. */
866 if (need_curr_point_incr)
867 next_program_point (curr_point, freq);
868
869 sparseset_clear (start_living);
870
871 need_curr_point_incr = false;
872
873 /* Mark each used value as live. */
874 for (reg = curr_id->regs; reg != NULL; reg = reg->next)
875 if (reg->type == OP_IN)
876 {
877 need_curr_point_incr |= mark_regno_live (reg->regno,
878 reg->biggest_mode,
879 curr_point, true);
880 check_pseudos_live_through_calls (reg->regno);
881 }
882
883 for (reg = curr_static_id->hard_regs; reg != NULL; reg = reg->next)
884 if (reg->type == OP_IN)
885 make_hard_regno_born (reg->regno);
886
887 if (curr_id->arg_hard_regs != NULL)
888 /* Make argument hard registers live. */
889 for (i = 0; (regno = curr_id->arg_hard_regs[i]) >= 0; i++)
890 make_hard_regno_born (regno);
891
892 sparseset_and_compl (dead_set, start_living, start_dying);
893
894 /* Mark early clobber outputs dead. */
895 for (reg = curr_id->regs; reg != NULL; reg = reg->next)
896 if (reg->type == OP_OUT && reg->early_clobber && ! reg->subreg_p)
897 need_curr_point_incr |= mark_regno_dead (reg->regno,
898 reg->biggest_mode,
899 curr_point, true);
900
901 for (reg = curr_static_id->hard_regs; reg != NULL; reg = reg->next)
902 if (reg->type == OP_OUT && reg->early_clobber && ! reg->subreg_p)
903 make_hard_regno_dead (reg->regno);
904
905 if (need_curr_point_incr)
906 next_program_point (curr_point, freq);
907
908 /* Update notes. */
909 for (link_loc = &REG_NOTES (curr_insn); (link = *link_loc) != NULL_RTX;)
910 {
911 if (REG_NOTE_KIND (link) != REG_DEAD
912 && REG_NOTE_KIND (link) != REG_UNUSED)
913 ;
914 else if (REG_P (XEXP (link, 0)))
915 {
916 regno = REGNO (XEXP (link, 0));
917 if ((REG_NOTE_KIND (link) == REG_DEAD
918 && ! sparseset_bit_p (dead_set, regno))
919 || (REG_NOTE_KIND (link) == REG_UNUSED
920 && ! sparseset_bit_p (unused_set, regno)))
921 {
922 *link_loc = XEXP (link, 1);
923 continue;
924 }
925 if (REG_NOTE_KIND (link) == REG_DEAD)
926 sparseset_clear_bit (dead_set, regno);
927 else if (REG_NOTE_KIND (link) == REG_UNUSED)
928 sparseset_clear_bit (unused_set, regno);
929 }
930 link_loc = &XEXP (link, 1);
931 }
932 EXECUTE_IF_SET_IN_SPARSESET (dead_set, j)
933 add_reg_note (curr_insn, REG_DEAD, regno_reg_rtx[j]);
934 EXECUTE_IF_SET_IN_SPARSESET (unused_set, j)
935 add_reg_note (curr_insn, REG_UNUSED, regno_reg_rtx[j]);
936 }
937
938 #ifdef EH_RETURN_DATA_REGNO
939 if (bb_has_eh_pred (bb))
940 for (j = 0; ; ++j)
941 {
942 unsigned int regno = EH_RETURN_DATA_REGNO (j);
943
944 if (regno == INVALID_REGNUM)
945 break;
946 make_hard_regno_born (regno);
947 }
948 #endif
949
950 /* Pseudos can't go in stack regs at the start of a basic block that
951 is reached by an abnormal edge. Likewise for call clobbered regs,
952 because caller-save, fixup_abnormal_edges and possibly the table
953 driven EH machinery are not quite ready to handle such pseudos
954 live across such edges. */
955 if (bb_has_abnormal_pred (bb))
956 {
957 #ifdef STACK_REGS
958 EXECUTE_IF_SET_IN_SPARSESET (pseudos_live, px)
959 lra_reg_info[px].no_stack_p = true;
960 for (px = FIRST_STACK_REG; px <= LAST_STACK_REG; px++)
961 make_hard_regno_born (px);
962 #endif
963 /* No need to record conflicts for call clobbered regs if we
964 have nonlocal labels around, as we don't ever try to
965 allocate such regs in this case. */
966 if (!cfun->has_nonlocal_label && bb_has_abnormal_call_pred (bb))
967 for (px = 0; px < FIRST_PSEUDO_REGISTER; px++)
968 if (call_used_regs[px])
969 make_hard_regno_born (px);
970 }
971
972 /* Check if bb border live info was changed. */
973 unsigned int live_pseudos_num = 0;
974 bool live_change_p = false;
975 EXECUTE_IF_SET_IN_BITMAP (df_get_live_in (bb), FIRST_PSEUDO_REGISTER, j, bi)
976 {
977 live_pseudos_num++;
978 if (! sparseset_bit_p (pseudos_live, j))
979 {
980 live_change_p = TRUE;
981 break;
982 }
983 }
984 live_change_p = live_change_p || sparseset_cardinality (pseudos_live) != live_pseudos_num;
985
986 /* See if we'll need an increment at the end of this basic block.
987 An increment is needed if the PSEUDOS_LIVE set is not empty,
988 to make sure the finish points are set up correctly. */
989 need_curr_point_incr = (sparseset_cardinality (pseudos_live) > 0);
990
991 EXECUTE_IF_SET_IN_SPARSESET (pseudos_live, i)
992 mark_pseudo_dead (i, curr_point);
993
994 EXECUTE_IF_SET_IN_BITMAP (df_get_live_in (bb), FIRST_PSEUDO_REGISTER, j, bi)
995 {
996 if (sparseset_cardinality (pseudos_live_through_calls) == 0)
997 break;
998 if (sparseset_bit_p (pseudos_live_through_calls, j))
999 check_pseudos_live_through_calls (j);
1000 }
1001
1002 if (need_curr_point_incr)
1003 next_program_point (curr_point, freq);
1004
1005 return live_change_p;
1006 }
1007
1008 /* Compress pseudo live ranges by removing program points where
1009 nothing happens. Complexity of many algorithms in LRA is linear
1010 function of program points number. To speed up the code we try to
1011 minimize the number of the program points here. */
1012 static void
1013 remove_some_program_points_and_update_live_ranges (void)
1014 {
1015 unsigned i;
1016 int n, max_regno;
1017 int *map;
1018 lra_live_range_t r, prev_r, next_r;
1019 sbitmap born_or_dead, born, dead;
1020 sbitmap_iterator sbi;
1021 bool born_p, dead_p, prev_born_p, prev_dead_p;
1022
1023 born = sbitmap_alloc (lra_live_max_point);
1024 dead = sbitmap_alloc (lra_live_max_point);
1025 bitmap_clear (born);
1026 bitmap_clear (dead);
1027 max_regno = max_reg_num ();
1028 for (i = FIRST_PSEUDO_REGISTER; i < (unsigned) max_regno; i++)
1029 {
1030 for (r = lra_reg_info[i].live_ranges; r != NULL; r = r->next)
1031 {
1032 lra_assert (r->start <= r->finish);
1033 bitmap_set_bit (born, r->start);
1034 bitmap_set_bit (dead, r->finish);
1035 }
1036 }
1037 born_or_dead = sbitmap_alloc (lra_live_max_point);
1038 bitmap_ior (born_or_dead, born, dead);
1039 map = XCNEWVEC (int, lra_live_max_point);
1040 n = -1;
1041 prev_born_p = prev_dead_p = false;
1042 EXECUTE_IF_SET_IN_BITMAP (born_or_dead, 0, i, sbi)
1043 {
1044 born_p = bitmap_bit_p (born, i);
1045 dead_p = bitmap_bit_p (dead, i);
1046 if ((prev_born_p && ! prev_dead_p && born_p && ! dead_p)
1047 || (prev_dead_p && ! prev_born_p && dead_p && ! born_p))
1048 {
1049 map[i] = n;
1050 lra_point_freq[n] = MAX (lra_point_freq[n], lra_point_freq[i]);
1051 }
1052 else
1053 {
1054 map[i] = ++n;
1055 lra_point_freq[n] = lra_point_freq[i];
1056 }
1057 prev_born_p = born_p;
1058 prev_dead_p = dead_p;
1059 }
1060 sbitmap_free (born_or_dead);
1061 sbitmap_free (born);
1062 sbitmap_free (dead);
1063 n++;
1064 if (lra_dump_file != NULL)
1065 fprintf (lra_dump_file, "Compressing live ranges: from %d to %d - %d%%\n",
1066 lra_live_max_point, n, 100 * n / lra_live_max_point);
1067 if (n < lra_live_max_point)
1068 {
1069 lra_live_max_point = n;
1070 for (i = FIRST_PSEUDO_REGISTER; i < (unsigned) max_regno; i++)
1071 {
1072 for (prev_r = NULL, r = lra_reg_info[i].live_ranges;
1073 r != NULL;
1074 r = next_r)
1075 {
1076 next_r = r->next;
1077 r->start = map[r->start];
1078 r->finish = map[r->finish];
1079 if (prev_r == NULL || prev_r->start > r->finish + 1)
1080 {
1081 prev_r = r;
1082 continue;
1083 }
1084 prev_r->start = r->start;
1085 prev_r->next = next_r;
1086 free_live_range (r);
1087 }
1088 }
1089 }
1090 free (map);
1091 }
1092
1093 /* Print live ranges R to file F. */
1094 void
1095 lra_print_live_range_list (FILE *f, lra_live_range_t r)
1096 {
1097 for (; r != NULL; r = r->next)
1098 fprintf (f, " [%d..%d]", r->start, r->finish);
1099 fprintf (f, "\n");
1100 }
1101
1102 DEBUG_FUNCTION void
1103 debug (lra_live_range &ref)
1104 {
1105 lra_print_live_range_list (stderr, &ref);
1106 }
1107
1108 DEBUG_FUNCTION void
1109 debug (lra_live_range *ptr)
1110 {
1111 if (ptr)
1112 debug (*ptr);
1113 else
1114 fprintf (stderr, "<nil>\n");
1115 }
1116
1117 /* Print live ranges R to stderr. */
1118 void
1119 lra_debug_live_range_list (lra_live_range_t r)
1120 {
1121 lra_print_live_range_list (stderr, r);
1122 }
1123
1124 /* Print live ranges of pseudo REGNO to file F. */
1125 static void
1126 print_pseudo_live_ranges (FILE *f, int regno)
1127 {
1128 if (lra_reg_info[regno].live_ranges == NULL)
1129 return;
1130 fprintf (f, " r%d:", regno);
1131 lra_print_live_range_list (f, lra_reg_info[regno].live_ranges);
1132 }
1133
1134 /* Print live ranges of pseudo REGNO to stderr. */
1135 void
1136 lra_debug_pseudo_live_ranges (int regno)
1137 {
1138 print_pseudo_live_ranges (stderr, regno);
1139 }
1140
1141 /* Print live ranges of all pseudos to file F. */
1142 static void
1143 print_live_ranges (FILE *f)
1144 {
1145 int i, max_regno;
1146
1147 max_regno = max_reg_num ();
1148 for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
1149 print_pseudo_live_ranges (f, i);
1150 }
1151
1152 /* Print live ranges of all pseudos to stderr. */
1153 void
1154 lra_debug_live_ranges (void)
1155 {
1156 print_live_ranges (stderr);
1157 }
1158
1159 /* Compress pseudo live ranges. */
1160 static void
1161 compress_live_ranges (void)
1162 {
1163 remove_some_program_points_and_update_live_ranges ();
1164 if (lra_dump_file != NULL)
1165 {
1166 fprintf (lra_dump_file, "Ranges after the compression:\n");
1167 print_live_ranges (lra_dump_file);
1168 }
1169 }
1170
1171 \f
1172
1173 /* The number of the current live range pass. */
1174 int lra_live_range_iter;
1175
1176 /* The main entry function creates live ranges only for memory pseudos
1177 (or for all ones if ALL_P), set up CONFLICT_HARD_REGS for the
1178 pseudos. It also does global live analysis only for pseudos and
1179 only if the pseudo live info was changed on a BB border. */
1180 void
1181 lra_create_live_ranges (bool all_p)
1182 {
1183 basic_block bb;
1184 int i, hard_regno, max_regno = max_reg_num ();
1185 int curr_point;
1186 bool bb_live_change_p, have_referenced_pseudos = false;
1187
1188 timevar_push (TV_LRA_CREATE_LIVE_RANGES);
1189
1190 complete_info_p = all_p;
1191 if (lra_dump_file != NULL)
1192 fprintf (lra_dump_file,
1193 "\n********** Pseudo live ranges #%d: **********\n\n",
1194 ++lra_live_range_iter);
1195 memset (lra_hard_reg_usage, 0, sizeof (lra_hard_reg_usage));
1196 for (i = 0; i < max_regno; i++)
1197 {
1198 lra_reg_info[i].live_ranges = NULL;
1199 CLEAR_HARD_REG_SET (lra_reg_info[i].conflict_hard_regs);
1200 lra_reg_info[i].preferred_hard_regno1 = -1;
1201 lra_reg_info[i].preferred_hard_regno2 = -1;
1202 lra_reg_info[i].preferred_hard_regno_profit1 = 0;
1203 lra_reg_info[i].preferred_hard_regno_profit2 = 0;
1204 #ifdef STACK_REGS
1205 lra_reg_info[i].no_stack_p = false;
1206 #endif
1207 /* The biggest mode is already set but its value might be to
1208 conservative because of recent transformation. Here in this
1209 file we recalculate it again as it costs practically
1210 nothing. */
1211 if (regno_reg_rtx[i] != NULL_RTX)
1212 lra_reg_info[i].biggest_mode = GET_MODE (regno_reg_rtx[i]);
1213 else
1214 lra_reg_info[i].biggest_mode = VOIDmode;
1215 #ifdef ENABLE_CHECKING
1216 lra_reg_info[i].call_p = false;
1217 #endif
1218 if (i >= FIRST_PSEUDO_REGISTER
1219 && lra_reg_info[i].nrefs != 0)
1220 {
1221 if ((hard_regno = reg_renumber[i]) >= 0)
1222 lra_hard_reg_usage[hard_regno] += lra_reg_info[i].freq;
1223 have_referenced_pseudos = true;
1224 }
1225 }
1226 lra_free_copies ();
1227
1228 /* Under some circumstances, we can have functions without pseudo
1229 registers. For such functions, lra_live_max_point will be 0,
1230 see e.g. PR55604, and there's nothing more to do for us here. */
1231 if (! have_referenced_pseudos)
1232 {
1233 timevar_pop (TV_LRA_CREATE_LIVE_RANGES);
1234 return;
1235 }
1236
1237 pseudos_live = sparseset_alloc (max_regno);
1238 pseudos_live_through_calls = sparseset_alloc (max_regno);
1239 pseudos_live_through_setjumps = sparseset_alloc (max_regno);
1240 start_living = sparseset_alloc (max_regno);
1241 start_dying = sparseset_alloc (max_regno);
1242 dead_set = sparseset_alloc (max_regno);
1243 unused_set = sparseset_alloc (max_regno);
1244 curr_point = 0;
1245 point_freq_vec.create (get_max_uid () * 2);
1246 lra_point_freq = point_freq_vec.address ();
1247 int *post_order_rev_cfg = XNEWVEC (int, last_basic_block_for_fn (cfun));
1248 int n_blocks_inverted = inverted_post_order_compute (post_order_rev_cfg);
1249 lra_assert (n_blocks_inverted == n_basic_blocks_for_fn (cfun));
1250 bb_live_change_p = false;
1251 for (i = n_blocks_inverted - 1; i >= 0; --i)
1252 {
1253 bb = BASIC_BLOCK_FOR_FN (cfun, post_order_rev_cfg[i]);
1254 if (bb == EXIT_BLOCK_PTR_FOR_FN (cfun) || bb
1255 == ENTRY_BLOCK_PTR_FOR_FN (cfun))
1256 continue;
1257 if (process_bb_lives (bb, curr_point))
1258 bb_live_change_p = true;
1259 }
1260 if (bb_live_change_p)
1261 {
1262 /* We need to clear pseudo live info as some pseudos can
1263 disappear, e.g. pseudos with used equivalences. */
1264 FOR_EACH_BB_FN (bb, cfun)
1265 {
1266 bitmap_clear_range (df_get_live_in (bb), FIRST_PSEUDO_REGISTER,
1267 max_regno - FIRST_PSEUDO_REGISTER);
1268 bitmap_clear_range (df_get_live_out (bb), FIRST_PSEUDO_REGISTER,
1269 max_regno - FIRST_PSEUDO_REGISTER);
1270 }
1271 /* As we did not change CFG since LRA start we can use
1272 DF-infrastructure solver to solve live data flow problem. */
1273 df_simple_dataflow
1274 (DF_BACKWARD, NULL, live_con_fun_0, live_con_fun_n,
1275 live_trans_fun, &all_blocks,
1276 df_get_postorder (DF_BACKWARD), df_get_n_blocks (DF_BACKWARD));
1277 if (lra_dump_file != NULL)
1278 {
1279 fprintf (lra_dump_file,
1280 "Global pseudo live data have been updated:\n");
1281 basic_block bb;
1282 FOR_EACH_BB_FN (bb, cfun)
1283 {
1284 bb_data_t bb_info = get_bb_data (bb);
1285 bitmap bb_livein = df_get_live_in (bb);
1286 bitmap bb_liveout = df_get_live_out (bb);
1287
1288 fprintf (lra_dump_file, "\nBB %d:\n", bb->index);
1289 lra_dump_bitmap_with_title (" gen:",
1290 &bb_info->gen_pseudos, bb->index);
1291 lra_dump_bitmap_with_title (" killed:",
1292 &bb_info->killed_pseudos, bb->index);
1293 lra_dump_bitmap_with_title (" livein:", bb_livein, bb->index);
1294 lra_dump_bitmap_with_title (" liveout:", bb_liveout, bb->index);
1295 }
1296 }
1297 }
1298 free (post_order_rev_cfg);
1299 lra_live_max_point = curr_point;
1300 if (lra_dump_file != NULL)
1301 print_live_ranges (lra_dump_file);
1302 /* Clean up. */
1303 sparseset_free (unused_set);
1304 sparseset_free (dead_set);
1305 sparseset_free (start_dying);
1306 sparseset_free (start_living);
1307 sparseset_free (pseudos_live_through_calls);
1308 sparseset_free (pseudos_live_through_setjumps);
1309 sparseset_free (pseudos_live);
1310 compress_live_ranges ();
1311 timevar_pop (TV_LRA_CREATE_LIVE_RANGES);
1312 }
1313
1314 /* Finish all live ranges. */
1315 void
1316 lra_clear_live_ranges (void)
1317 {
1318 int i;
1319
1320 for (i = 0; i < max_reg_num (); i++)
1321 free_live_range_list (lra_reg_info[i].live_ranges);
1322 point_freq_vec.release ();
1323 }
1324
1325 /* Initialize live ranges data once per function. */
1326 void
1327 lra_live_ranges_init (void)
1328 {
1329 live_range_pool = create_alloc_pool ("live ranges",
1330 sizeof (struct lra_live_range), 100);
1331 initiate_live_solver ();
1332 }
1333
1334 /* Finish live ranges data once per function. */
1335 void
1336 lra_live_ranges_finish (void)
1337 {
1338 finish_live_solver ();
1339 free_alloc_pool (live_range_pool);
1340 }