2015-09-01 Vladimir Makarov <vmakarov@redhat.com>
[official-gcc.git] / gcc / lra-lives.c
blob1da5204da45cb403d90cd5ac0538cac1e0b3797a
1 /* Build live ranges for pseudos.
2 Copyright (C) 2010-2015 Free Software Foundation, Inc.
3 Contributed by Vladimir Makarov <vmakarov@redhat.com>.
5 This file is part of GCC.
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.
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.
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/>. */
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. */
28 #include "config.h"
29 #include "system.h"
30 #include "coretypes.h"
31 #include "backend.h"
32 #include "predict.h"
33 #include "tree.h"
34 #include "rtl.h"
35 #include "df.h"
36 #include "tm_p.h"
37 #include "insn-config.h"
38 #include "recog.h"
39 #include "output.h"
40 #include "regs.h"
41 #include "flags.h"
42 #include "alias.h"
43 #include "expmed.h"
44 #include "dojump.h"
45 #include "explow.h"
46 #include "calls.h"
47 #include "emit-rtl.h"
48 #include "varasm.h"
49 #include "stmt.h"
50 #include "expr.h"
51 #include "cfganal.h"
52 #include "except.h"
53 #include "ira.h"
54 #include "sparseset.h"
55 #include "lra.h"
56 #include "insn-attr.h"
57 #include "insn-codes.h"
58 #include "lra-int.h"
60 /* Program points are enumerated by numbers from range
61 0..LRA_LIVE_MAX_POINT-1. There are approximately two times more
62 program points than insns. Program points are places in the
63 program where liveness info can be changed. In most general case
64 (there are more complicated cases too) some program points
65 correspond to places where input operand dies and other ones
66 correspond to places where output operands are born. */
67 int lra_live_max_point;
69 /* Accumulated execution frequency of all references for each hard
70 register. */
71 int lra_hard_reg_usage[FIRST_PSEUDO_REGISTER];
73 /* A global flag whose true value says to build live ranges for all
74 pseudos, otherwise the live ranges only for pseudos got memory is
75 build. True value means also building copies and setting up hard
76 register preferences. The complete info is necessary only for the
77 assignment pass. The complete info is not needed for the
78 coalescing and spill passes. */
79 static bool complete_info_p;
81 /* Pseudos live at current point in the RTL scan. */
82 static sparseset pseudos_live;
84 /* Pseudos probably living through calls and setjumps. As setjump is
85 a call too, if a bit in PSEUDOS_LIVE_THROUGH_SETJUMPS is set up
86 then the corresponding bit in PSEUDOS_LIVE_THROUGH_CALLS is set up
87 too. These data are necessary for cases when only one subreg of a
88 multi-reg pseudo is set up after a call. So we decide it is
89 probably live when traversing bb backward. We are sure about
90 living when we see its usage or definition of the pseudo. */
91 static sparseset pseudos_live_through_calls;
92 static sparseset pseudos_live_through_setjumps;
94 /* Set of hard regs (except eliminable ones) currently live. */
95 static HARD_REG_SET hard_regs_live;
97 /* Set of pseudos and hard registers start living/dying in the current
98 insn. These sets are used to update REG_DEAD and REG_UNUSED notes
99 in the insn. */
100 static sparseset start_living, start_dying;
102 /* Set of pseudos and hard regs dead and unused in the current
103 insn. */
104 static sparseset unused_set, dead_set;
106 /* Bitmap used for holding intermediate bitmap operation results. */
107 static bitmap_head temp_bitmap;
109 /* Pool for pseudo live ranges. */
110 static object_allocator<lra_live_range> lra_live_range_pool
111 ("live ranges", 100);
113 /* Free live range list LR. */
114 static void
115 free_live_range_list (lra_live_range_t lr)
117 lra_live_range_t next;
119 while (lr != NULL)
121 next = lr->next;
122 delete lr;
123 lr = next;
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)
131 lra_live_range_t p = new lra_live_range;
132 p->regno = regno;
133 p->start = start;
134 p->finish = finish;
135 p->next = next;
136 return p;
139 /* Copy live range R and return the result. */
140 static lra_live_range_t
141 copy_live_range (lra_live_range_t r)
143 return new lra_live_range (*r);
146 /* Copy live range list given by its head R and return the result. */
147 lra_live_range_t
148 lra_copy_live_range_list (lra_live_range_t r)
150 lra_live_range_t p, first, *chain;
152 first = NULL;
153 for (chain = &first; r != NULL; r = r->next)
155 p = copy_live_range (r);
156 *chain = p;
157 chain = &p->next;
159 return first;
162 /* Merge *non-intersected* ranges R1 and R2 and returns the result.
163 The function maintains the order of ranges and tries to minimize
164 size of the result range list. Ranges R1 and R2 may not be used
165 after the call. */
166 lra_live_range_t
167 lra_merge_live_ranges (lra_live_range_t r1, lra_live_range_t r2)
169 lra_live_range_t first, last;
171 if (r1 == NULL)
172 return r2;
173 if (r2 == NULL)
174 return r1;
175 for (first = last = NULL; r1 != NULL && r2 != NULL;)
177 if (r1->start < r2->start)
178 std::swap (r1, r2);
180 if (r1->start == r2->finish + 1)
182 /* Joint ranges: merge r1 and r2 into r1. */
183 r1->start = r2->start;
184 lra_live_range_t temp = r2;
185 r2 = r2->next;
186 delete temp;
188 else
190 gcc_assert (r2->finish + 1 < r1->start);
191 /* Add r1 to the result. */
192 if (first == NULL)
193 first = last = r1;
194 else
196 last->next = r1;
197 last = r1;
199 r1 = r1->next;
202 if (r1 != NULL)
204 if (first == NULL)
205 first = r1;
206 else
207 last->next = r1;
209 else
211 lra_assert (r2 != NULL);
212 if (first == NULL)
213 first = r2;
214 else
215 last->next = r2;
217 return first;
220 /* Return TRUE if live ranges R1 and R2 intersect. */
221 bool
222 lra_intersected_live_ranges_p (lra_live_range_t r1, lra_live_range_t r2)
224 /* Remember the live ranges are always kept ordered. */
225 while (r1 != NULL && r2 != NULL)
227 if (r1->start > r2->finish)
228 r1 = r1->next;
229 else if (r2->start > r1->finish)
230 r2 = r2->next;
231 else
232 return true;
234 return false;
237 /* The function processing birth of hard register REGNO. It updates
238 living hard regs, START_LIVING, and conflict hard regs for living
239 pseudos. Conflict hard regs for the pic pseudo is not updated if
240 REGNO is REAL_PIC_OFFSET_TABLE_REGNUM and CHECK_PIC_PSEUDO_P is
241 true. */
242 static void
243 make_hard_regno_born (int regno, bool check_pic_pseudo_p ATTRIBUTE_UNUSED)
245 unsigned int i;
247 lra_assert (regno < FIRST_PSEUDO_REGISTER);
248 if (TEST_HARD_REG_BIT (hard_regs_live, regno))
249 return;
250 SET_HARD_REG_BIT (hard_regs_live, regno);
251 sparseset_set_bit (start_living, regno);
252 EXECUTE_IF_SET_IN_SPARSESET (pseudos_live, i)
253 #ifdef REAL_PIC_OFFSET_TABLE_REGNUM
254 if (! check_pic_pseudo_p
255 || regno != REAL_PIC_OFFSET_TABLE_REGNUM
256 || pic_offset_table_rtx == NULL
257 || i != REGNO (pic_offset_table_rtx))
258 #endif
259 SET_HARD_REG_BIT (lra_reg_info[i].conflict_hard_regs, regno);
262 /* Process the death of hard register REGNO. This updates
263 hard_regs_live and START_DYING. */
264 static void
265 make_hard_regno_dead (int regno)
267 lra_assert (regno < FIRST_PSEUDO_REGISTER);
268 if (! TEST_HARD_REG_BIT (hard_regs_live, regno))
269 return;
270 sparseset_set_bit (start_dying, regno);
271 CLEAR_HARD_REG_BIT (hard_regs_live, regno);
274 /* Mark pseudo REGNO as living at program point POINT, update conflicting
275 hard registers of the pseudo and START_LIVING, and start a new live
276 range for the pseudo corresponding to REGNO if it is necessary. */
277 static void
278 mark_pseudo_live (int regno, int point)
280 lra_live_range_t p;
282 lra_assert (regno >= FIRST_PSEUDO_REGISTER);
283 lra_assert (! sparseset_bit_p (pseudos_live, regno));
284 sparseset_set_bit (pseudos_live, regno);
285 IOR_HARD_REG_SET (lra_reg_info[regno].conflict_hard_regs, hard_regs_live);
287 if ((complete_info_p || lra_get_regno_hard_regno (regno) < 0)
288 && ((p = lra_reg_info[regno].live_ranges) == NULL
289 || (p->finish != point && p->finish + 1 != point)))
290 lra_reg_info[regno].live_ranges
291 = create_live_range (regno, point, -1, p);
292 sparseset_set_bit (start_living, regno);
295 /* Mark pseudo REGNO as not living at program point POINT and update
296 START_DYING.
297 This finishes the current live range for the pseudo corresponding
298 to REGNO. */
299 static void
300 mark_pseudo_dead (int regno, int point)
302 lra_live_range_t p;
304 lra_assert (regno >= FIRST_PSEUDO_REGISTER);
305 lra_assert (sparseset_bit_p (pseudos_live, regno));
306 sparseset_clear_bit (pseudos_live, regno);
307 sparseset_set_bit (start_dying, regno);
308 if (complete_info_p || lra_get_regno_hard_regno (regno) < 0)
310 p = lra_reg_info[regno].live_ranges;
311 lra_assert (p != NULL);
312 p->finish = point;
316 /* The corresponding bitmaps of BB currently being processed. */
317 static bitmap bb_killed_pseudos, bb_gen_pseudos;
319 /* Mark register REGNO (pseudo or hard register) in MODE as live at
320 program point POINT. Update BB_GEN_PSEUDOS.
321 Return TRUE if the liveness tracking sets were modified, or FALSE
322 if nothing changed. */
323 static bool
324 mark_regno_live (int regno, machine_mode mode, int point)
326 int last;
327 bool changed = false;
329 if (regno < FIRST_PSEUDO_REGISTER)
331 for (last = regno + hard_regno_nregs[regno][mode];
332 regno < last;
333 regno++)
334 make_hard_regno_born (regno, false);
336 else
338 if (! sparseset_bit_p (pseudos_live, regno))
340 mark_pseudo_live (regno, point);
341 changed = true;
343 bitmap_set_bit (bb_gen_pseudos, regno);
345 return changed;
349 /* Mark register REGNO in MODE as dead at program point POINT. Update
350 BB_GEN_PSEUDOS and BB_KILLED_PSEUDOS. Return TRUE if the liveness
351 tracking sets were modified, or FALSE if nothing changed. */
352 static bool
353 mark_regno_dead (int regno, machine_mode mode, int point)
355 int last;
356 bool changed = false;
358 if (regno < FIRST_PSEUDO_REGISTER)
360 for (last = regno + hard_regno_nregs[regno][mode];
361 regno < last;
362 regno++)
363 make_hard_regno_dead (regno);
365 else
367 if (sparseset_bit_p (pseudos_live, regno))
369 mark_pseudo_dead (regno, point);
370 changed = true;
372 bitmap_clear_bit (bb_gen_pseudos, regno);
373 bitmap_set_bit (bb_killed_pseudos, regno);
375 return changed;
380 /* This page contains code for making global live analysis of pseudos.
381 The code works only when pseudo live info is changed on a BB
382 border. That might be a consequence of some global transformations
383 in LRA, e.g. PIC pseudo reuse or rematerialization. */
385 /* Structure describing local BB data used for pseudo
386 live-analysis. */
387 struct bb_data_pseudos
389 /* Basic block about which the below data are. */
390 basic_block bb;
391 bitmap_head killed_pseudos; /* pseudos killed in the BB. */
392 bitmap_head gen_pseudos; /* pseudos generated in the BB. */
395 /* Array for all BB data. Indexed by the corresponding BB index. */
396 typedef struct bb_data_pseudos *bb_data_t;
398 /* All basic block data are referred through the following array. */
399 static bb_data_t bb_data;
401 /* Two small functions for access to the bb data. */
402 static inline bb_data_t
403 get_bb_data (basic_block bb)
405 return &bb_data[(bb)->index];
408 static inline bb_data_t
409 get_bb_data_by_index (int index)
411 return &bb_data[index];
414 /* Bitmap with all hard regs. */
415 static bitmap_head all_hard_regs_bitmap;
417 /* The transfer function used by the DF equation solver to propagate
418 live info through block with BB_INDEX according to the following
419 equation:
421 bb.livein = (bb.liveout - bb.kill) OR bb.gen
423 static bool
424 live_trans_fun (int bb_index)
426 basic_block bb = get_bb_data_by_index (bb_index)->bb;
427 bitmap bb_liveout = df_get_live_out (bb);
428 bitmap bb_livein = df_get_live_in (bb);
429 bb_data_t bb_info = get_bb_data (bb);
431 bitmap_and_compl (&temp_bitmap, bb_liveout, &all_hard_regs_bitmap);
432 return bitmap_ior_and_compl (bb_livein, &bb_info->gen_pseudos,
433 &temp_bitmap, &bb_info->killed_pseudos);
436 /* The confluence function used by the DF equation solver to set up
437 live info for a block BB without predecessor. */
438 static void
439 live_con_fun_0 (basic_block bb)
441 bitmap_and_into (df_get_live_out (bb), &all_hard_regs_bitmap);
444 /* The confluence function used by the DF equation solver to propagate
445 live info from successor to predecessor on edge E according to the
446 following equation:
448 bb.liveout = 0 for entry block | OR (livein of successors)
450 static bool
451 live_con_fun_n (edge e)
453 basic_block bb = e->src;
454 basic_block dest = e->dest;
455 bitmap bb_liveout = df_get_live_out (bb);
456 bitmap dest_livein = df_get_live_in (dest);
458 return bitmap_ior_and_compl_into (bb_liveout,
459 dest_livein, &all_hard_regs_bitmap);
462 /* Indexes of all function blocks. */
463 static bitmap_head all_blocks;
465 /* Allocate and initialize data needed for global pseudo live
466 analysis. */
467 static void
468 initiate_live_solver (void)
470 bitmap_initialize (&all_hard_regs_bitmap, &reg_obstack);
471 bitmap_set_range (&all_hard_regs_bitmap, 0, FIRST_PSEUDO_REGISTER);
472 bb_data = XNEWVEC (struct bb_data_pseudos, last_basic_block_for_fn (cfun));
473 bitmap_initialize (&all_blocks, &reg_obstack);
475 basic_block bb;
476 FOR_ALL_BB_FN (bb, cfun)
478 bb_data_t bb_info = get_bb_data (bb);
479 bb_info->bb = bb;
480 bitmap_initialize (&bb_info->killed_pseudos, &reg_obstack);
481 bitmap_initialize (&bb_info->gen_pseudos, &reg_obstack);
482 bitmap_set_bit (&all_blocks, bb->index);
486 /* Free all data needed for global pseudo live analysis. */
487 static void
488 finish_live_solver (void)
490 basic_block bb;
492 bitmap_clear (&all_blocks);
493 FOR_ALL_BB_FN (bb, cfun)
495 bb_data_t bb_info = get_bb_data (bb);
496 bitmap_clear (&bb_info->killed_pseudos);
497 bitmap_clear (&bb_info->gen_pseudos);
499 free (bb_data);
500 bitmap_clear (&all_hard_regs_bitmap);
505 /* Insn currently scanned. */
506 static rtx_insn *curr_insn;
507 /* The insn data. */
508 static lra_insn_recog_data_t curr_id;
509 /* The insn static data. */
510 static struct lra_static_insn_data *curr_static_id;
512 /* Vec containing execution frequencies of program points. */
513 static vec<int> point_freq_vec;
515 /* The start of the above vector elements. */
516 int *lra_point_freq;
518 /* Increment the current program point POINT to the next point which has
519 execution frequency FREQ. */
520 static void
521 next_program_point (int &point, int freq)
523 point_freq_vec.safe_push (freq);
524 lra_point_freq = point_freq_vec.address ();
525 point++;
528 /* Update the preference of HARD_REGNO for pseudo REGNO by PROFIT. */
529 void
530 lra_setup_reload_pseudo_preferenced_hard_reg (int regno,
531 int hard_regno, int profit)
533 lra_assert (regno >= lra_constraint_new_regno_start);
534 if (lra_reg_info[regno].preferred_hard_regno1 == hard_regno)
535 lra_reg_info[regno].preferred_hard_regno_profit1 += profit;
536 else if (lra_reg_info[regno].preferred_hard_regno2 == hard_regno)
537 lra_reg_info[regno].preferred_hard_regno_profit2 += profit;
538 else if (lra_reg_info[regno].preferred_hard_regno1 < 0)
540 lra_reg_info[regno].preferred_hard_regno1 = hard_regno;
541 lra_reg_info[regno].preferred_hard_regno_profit1 = profit;
543 else if (lra_reg_info[regno].preferred_hard_regno2 < 0
544 || profit > lra_reg_info[regno].preferred_hard_regno_profit2)
546 lra_reg_info[regno].preferred_hard_regno2 = hard_regno;
547 lra_reg_info[regno].preferred_hard_regno_profit2 = profit;
549 else
550 return;
551 /* Keep the 1st hard regno as more profitable. */
552 if (lra_reg_info[regno].preferred_hard_regno1 >= 0
553 && lra_reg_info[regno].preferred_hard_regno2 >= 0
554 && (lra_reg_info[regno].preferred_hard_regno_profit2
555 > lra_reg_info[regno].preferred_hard_regno_profit1))
557 std::swap (lra_reg_info[regno].preferred_hard_regno1,
558 lra_reg_info[regno].preferred_hard_regno2);
559 std::swap (lra_reg_info[regno].preferred_hard_regno_profit1,
560 lra_reg_info[regno].preferred_hard_regno_profit2);
562 if (lra_dump_file != NULL)
564 if ((hard_regno = lra_reg_info[regno].preferred_hard_regno1) >= 0)
565 fprintf (lra_dump_file,
566 " Hard reg %d is preferable by r%d with profit %d\n",
567 hard_regno, regno,
568 lra_reg_info[regno].preferred_hard_regno_profit1);
569 if ((hard_regno = lra_reg_info[regno].preferred_hard_regno2) >= 0)
570 fprintf (lra_dump_file,
571 " Hard reg %d is preferable by r%d with profit %d\n",
572 hard_regno, regno,
573 lra_reg_info[regno].preferred_hard_regno_profit2);
577 /* Check that REGNO living through calls and setjumps, set up conflict
578 regs, and clear corresponding bits in PSEUDOS_LIVE_THROUGH_CALLS and
579 PSEUDOS_LIVE_THROUGH_SETJUMPS. */
580 static inline void
581 check_pseudos_live_through_calls (int regno)
583 int hr;
585 if (! sparseset_bit_p (pseudos_live_through_calls, regno))
586 return;
587 sparseset_clear_bit (pseudos_live_through_calls, regno);
588 IOR_HARD_REG_SET (lra_reg_info[regno].conflict_hard_regs,
589 call_used_reg_set);
591 for (hr = 0; hr < FIRST_PSEUDO_REGISTER; hr++)
592 if (HARD_REGNO_CALL_PART_CLOBBERED (hr, PSEUDO_REGNO_MODE (regno)))
593 SET_HARD_REG_BIT (lra_reg_info[regno].conflict_hard_regs, hr);
594 #ifdef ENABLE_CHECKING
595 lra_reg_info[regno].call_p = true;
596 #endif
597 if (! sparseset_bit_p (pseudos_live_through_setjumps, regno))
598 return;
599 sparseset_clear_bit (pseudos_live_through_setjumps, regno);
600 /* Don't allocate pseudos that cross setjmps or any call, if this
601 function receives a nonlocal goto. */
602 SET_HARD_REG_SET (lra_reg_info[regno].conflict_hard_regs);
605 /* Process insns of the basic block BB to update pseudo live ranges,
606 pseudo hard register conflicts, and insn notes. We do it on
607 backward scan of BB insns. CURR_POINT is the program point where
608 BB ends. The function updates this counter and returns in
609 CURR_POINT the program point where BB starts. The function also
610 does local live info updates and can delete the dead insns if
611 DEAD_INSN_P. It returns true if pseudo live info was
612 changed at the BB start. */
613 static bool
614 process_bb_lives (basic_block bb, int &curr_point, bool dead_insn_p)
616 int i, regno, freq;
617 unsigned int j;
618 bitmap_iterator bi;
619 bitmap reg_live_out;
620 unsigned int px;
621 rtx_insn *next;
622 rtx link, *link_loc;
623 bool need_curr_point_incr;
625 reg_live_out = df_get_live_out (bb);
626 sparseset_clear (pseudos_live);
627 sparseset_clear (pseudos_live_through_calls);
628 sparseset_clear (pseudos_live_through_setjumps);
629 REG_SET_TO_HARD_REG_SET (hard_regs_live, reg_live_out);
630 AND_COMPL_HARD_REG_SET (hard_regs_live, eliminable_regset);
631 EXECUTE_IF_SET_IN_BITMAP (reg_live_out, FIRST_PSEUDO_REGISTER, j, bi)
632 mark_pseudo_live (j, curr_point);
634 bb_gen_pseudos = &get_bb_data (bb)->gen_pseudos;
635 bb_killed_pseudos = &get_bb_data (bb)->killed_pseudos;
636 bitmap_clear (bb_gen_pseudos);
637 bitmap_clear (bb_killed_pseudos);
638 freq = REG_FREQ_FROM_BB (bb);
640 if (lra_dump_file != NULL)
641 fprintf (lra_dump_file, " BB %d\n", bb->index);
643 /* Scan the code of this basic block, noting which pseudos and hard
644 regs are born or die.
646 Note that this loop treats uninitialized values as live until the
647 beginning of the block. For example, if an instruction uses
648 (reg:DI foo), and only (subreg:SI (reg:DI foo) 0) is ever set,
649 FOO will remain live until the beginning of the block. Likewise
650 if FOO is not set at all. This is unnecessarily pessimistic, but
651 it probably doesn't matter much in practice. */
652 FOR_BB_INSNS_REVERSE_SAFE (bb, curr_insn, next)
654 bool call_p;
655 int dst_regno, src_regno;
656 rtx set;
657 struct lra_insn_reg *reg;
659 if (!NONDEBUG_INSN_P (curr_insn))
660 continue;
662 curr_id = lra_get_insn_recog_data (curr_insn);
663 curr_static_id = curr_id->insn_static_data;
664 if (lra_dump_file != NULL)
665 fprintf (lra_dump_file, " Insn %u: point = %d\n",
666 INSN_UID (curr_insn), curr_point);
668 set = single_set (curr_insn);
670 if (dead_insn_p && set != NULL_RTX
671 && REG_P (SET_DEST (set)) && REGNO (SET_DEST (set)) >= FIRST_PSEUDO_REGISTER
672 && find_reg_note (curr_insn, REG_EH_REGION, NULL_RTX) == NULL_RTX
673 && ! may_trap_p (PATTERN (curr_insn))
674 /* Don't do premature remove of pic offset pseudo as we can
675 start to use it after some reload generation. */
676 && (pic_offset_table_rtx == NULL_RTX
677 || pic_offset_table_rtx != SET_DEST (set)))
679 bool remove_p = true;
681 for (reg = curr_id->regs; reg != NULL; reg = reg->next)
682 if (reg->type != OP_IN && sparseset_bit_p (pseudos_live, reg->regno))
684 remove_p = false;
685 break;
687 for (reg = curr_static_id->hard_regs; reg != NULL; reg = reg->next)
688 if (reg->type != OP_IN)
690 remove_p = false;
691 break;
693 if (remove_p && ! volatile_refs_p (PATTERN (curr_insn)))
695 dst_regno = REGNO (SET_DEST (set));
696 if (lra_dump_file != NULL)
697 fprintf (lra_dump_file, " Deleting dead insn %u\n",
698 INSN_UID (curr_insn));
699 lra_set_insn_deleted (curr_insn);
700 if (lra_reg_info[dst_regno].nrefs == 0)
702 /* There might be some debug insns with the pseudo. */
703 unsigned int uid;
704 rtx_insn *insn;
706 bitmap_copy (&temp_bitmap, &lra_reg_info[dst_regno].insn_bitmap);
707 EXECUTE_IF_SET_IN_BITMAP (&temp_bitmap, 0, uid, bi)
709 insn = lra_insn_recog_data[uid]->insn;
710 lra_substitute_pseudo_within_insn (insn, dst_regno,
711 SET_SRC (set), true);
712 lra_update_insn_regno_info (insn);
715 continue;
719 /* Update max ref width and hard reg usage. */
720 for (reg = curr_id->regs; reg != NULL; reg = reg->next)
721 if (reg->regno >= FIRST_PSEUDO_REGISTER
722 && (GET_MODE_SIZE (reg->biggest_mode)
723 > GET_MODE_SIZE (lra_reg_info[reg->regno].biggest_mode)))
724 lra_reg_info[reg->regno].biggest_mode = reg->biggest_mode;
725 else if (reg->regno < FIRST_PSEUDO_REGISTER)
726 lra_hard_reg_usage[reg->regno] += freq;
728 call_p = CALL_P (curr_insn);
729 src_regno = (set != NULL_RTX && REG_P (SET_SRC (set))
730 ? REGNO (SET_SRC (set)) : -1);
731 dst_regno = (set != NULL_RTX && REG_P (SET_DEST (set))
732 ? REGNO (SET_DEST (set)) : -1);
733 if (complete_info_p
734 && src_regno >= 0 && dst_regno >= 0
735 /* Check that source regno does not conflict with
736 destination regno to exclude most impossible
737 preferences. */
738 && (((src_regno >= FIRST_PSEUDO_REGISTER
739 && (! sparseset_bit_p (pseudos_live, src_regno)
740 || (dst_regno >= FIRST_PSEUDO_REGISTER
741 && lra_reg_val_equal_p (src_regno,
742 lra_reg_info[dst_regno].val,
743 lra_reg_info[dst_regno].offset))))
744 || (src_regno < FIRST_PSEUDO_REGISTER
745 && ! TEST_HARD_REG_BIT (hard_regs_live, src_regno)))
746 /* It might be 'inheritance pseudo <- reload pseudo'. */
747 || (src_regno >= lra_constraint_new_regno_start
748 && dst_regno >= lra_constraint_new_regno_start
749 /* Remember to skip special cases where src/dest regnos are
750 the same, e.g. insn SET pattern has matching constraints
751 like =r,0. */
752 && src_regno != dst_regno)))
754 int hard_regno = -1, regno = -1;
756 if (dst_regno >= lra_constraint_new_regno_start
757 && src_regno >= lra_constraint_new_regno_start)
759 /* It might be still an original (non-reload) insn with
760 one unused output and a constraint requiring to use
761 the same reg for input/output operands. In this case
762 dst_regno and src_regno have the same value, we don't
763 need a misleading copy for this case. */
764 if (dst_regno != src_regno)
765 lra_create_copy (dst_regno, src_regno, freq);
767 else if (dst_regno >= lra_constraint_new_regno_start)
769 if ((hard_regno = src_regno) >= FIRST_PSEUDO_REGISTER)
770 hard_regno = reg_renumber[src_regno];
771 regno = dst_regno;
773 else if (src_regno >= lra_constraint_new_regno_start)
775 if ((hard_regno = dst_regno) >= FIRST_PSEUDO_REGISTER)
776 hard_regno = reg_renumber[dst_regno];
777 regno = src_regno;
779 if (regno >= 0 && hard_regno >= 0)
780 lra_setup_reload_pseudo_preferenced_hard_reg
781 (regno, hard_regno, freq);
784 sparseset_clear (start_living);
786 /* Try to avoid unnecessary program point increments, this saves
787 a lot of time in remove_some_program_points_and_update_live_ranges.
788 We only need an increment if something becomes live or dies at this
789 program point. */
790 need_curr_point_incr = false;
792 /* Mark each defined value as live. We need to do this for
793 unused values because they still conflict with quantities
794 that are live at the time of the definition. */
795 for (reg = curr_id->regs; reg != NULL; reg = reg->next)
796 if (reg->type != OP_IN)
798 need_curr_point_incr
799 |= mark_regno_live (reg->regno, reg->biggest_mode,
800 curr_point);
801 check_pseudos_live_through_calls (reg->regno);
804 for (reg = curr_static_id->hard_regs; reg != NULL; reg = reg->next)
805 if (reg->type != OP_IN)
806 make_hard_regno_born (reg->regno, false);
808 if (curr_id->arg_hard_regs != NULL)
809 for (i = 0; (regno = curr_id->arg_hard_regs[i]) >= 0; i++)
810 if (regno >= FIRST_PSEUDO_REGISTER)
811 /* It is a clobber. */
812 make_hard_regno_born (regno - FIRST_PSEUDO_REGISTER, false);
814 sparseset_copy (unused_set, start_living);
816 sparseset_clear (start_dying);
818 /* See which defined values die here. */
819 for (reg = curr_id->regs; reg != NULL; reg = reg->next)
820 if (reg->type == OP_OUT && ! reg->early_clobber && ! reg->subreg_p)
821 need_curr_point_incr
822 |= mark_regno_dead (reg->regno, reg->biggest_mode,
823 curr_point);
825 for (reg = curr_static_id->hard_regs; reg != NULL; reg = reg->next)
826 if (reg->type == OP_OUT && ! reg->early_clobber && ! reg->subreg_p)
827 make_hard_regno_dead (reg->regno);
829 if (curr_id->arg_hard_regs != NULL)
830 for (i = 0; (regno = curr_id->arg_hard_regs[i]) >= 0; i++)
831 if (regno >= FIRST_PSEUDO_REGISTER)
832 /* It is a clobber. */
833 make_hard_regno_dead (regno - FIRST_PSEUDO_REGISTER);
835 if (call_p)
837 if (flag_ipa_ra)
839 HARD_REG_SET this_call_used_reg_set;
840 get_call_reg_set_usage (curr_insn, &this_call_used_reg_set,
841 call_used_reg_set);
843 EXECUTE_IF_SET_IN_SPARSESET (pseudos_live, j)
844 IOR_HARD_REG_SET (lra_reg_info[j].actual_call_used_reg_set,
845 this_call_used_reg_set);
848 sparseset_ior (pseudos_live_through_calls,
849 pseudos_live_through_calls, pseudos_live);
850 if (cfun->has_nonlocal_label
851 || find_reg_note (curr_insn, REG_SETJMP,
852 NULL_RTX) != NULL_RTX)
853 sparseset_ior (pseudos_live_through_setjumps,
854 pseudos_live_through_setjumps, pseudos_live);
857 /* Increment the current program point if we must. */
858 if (need_curr_point_incr)
859 next_program_point (curr_point, freq);
861 sparseset_clear (start_living);
863 need_curr_point_incr = false;
865 /* Mark each used value as live. */
866 for (reg = curr_id->regs; reg != NULL; reg = reg->next)
867 if (reg->type == OP_IN)
869 need_curr_point_incr
870 |= mark_regno_live (reg->regno, reg->biggest_mode,
871 curr_point);
872 check_pseudos_live_through_calls (reg->regno);
875 for (reg = curr_static_id->hard_regs; reg != NULL; reg = reg->next)
876 if (reg->type == OP_IN)
877 make_hard_regno_born (reg->regno, false);
879 if (curr_id->arg_hard_regs != NULL)
880 /* Make argument hard registers live. Don't create conflict
881 of used REAL_PIC_OFFSET_TABLE_REGNUM and the pic pseudo. */
882 for (i = 0; (regno = curr_id->arg_hard_regs[i]) >= 0; i++)
883 if (regno < FIRST_PSEUDO_REGISTER)
884 make_hard_regno_born (regno, true);
886 sparseset_and_compl (dead_set, start_living, start_dying);
888 /* Mark early clobber outputs dead. */
889 for (reg = curr_id->regs; reg != NULL; reg = reg->next)
890 if (reg->type == OP_OUT && reg->early_clobber && ! reg->subreg_p)
891 need_curr_point_incr
892 |= mark_regno_dead (reg->regno, reg->biggest_mode,
893 curr_point);
895 for (reg = curr_static_id->hard_regs; reg != NULL; reg = reg->next)
896 if (reg->type == OP_OUT && reg->early_clobber && ! reg->subreg_p)
897 make_hard_regno_dead (reg->regno);
899 if (need_curr_point_incr)
900 next_program_point (curr_point, freq);
902 /* Update notes. */
903 for (link_loc = &REG_NOTES (curr_insn); (link = *link_loc) != NULL_RTX;)
905 if (REG_NOTE_KIND (link) != REG_DEAD
906 && REG_NOTE_KIND (link) != REG_UNUSED)
908 else if (REG_P (XEXP (link, 0)))
910 regno = REGNO (XEXP (link, 0));
911 if ((REG_NOTE_KIND (link) == REG_DEAD
912 && ! sparseset_bit_p (dead_set, regno))
913 || (REG_NOTE_KIND (link) == REG_UNUSED
914 && ! sparseset_bit_p (unused_set, regno)))
916 *link_loc = XEXP (link, 1);
917 continue;
919 if (REG_NOTE_KIND (link) == REG_DEAD)
920 sparseset_clear_bit (dead_set, regno);
921 else if (REG_NOTE_KIND (link) == REG_UNUSED)
922 sparseset_clear_bit (unused_set, regno);
924 link_loc = &XEXP (link, 1);
926 EXECUTE_IF_SET_IN_SPARSESET (dead_set, j)
927 add_reg_note (curr_insn, REG_DEAD, regno_reg_rtx[j]);
928 EXECUTE_IF_SET_IN_SPARSESET (unused_set, j)
929 add_reg_note (curr_insn, REG_UNUSED, regno_reg_rtx[j]);
932 if (bb_has_eh_pred (bb))
933 for (j = 0; ; ++j)
935 unsigned int regno = EH_RETURN_DATA_REGNO (j);
937 if (regno == INVALID_REGNUM)
938 break;
939 make_hard_regno_born (regno, false);
942 /* Pseudos can't go in stack regs at the start of a basic block that
943 is reached by an abnormal edge. Likewise for call clobbered regs,
944 because caller-save, fixup_abnormal_edges and possibly the table
945 driven EH machinery are not quite ready to handle such pseudos
946 live across such edges. */
947 if (bb_has_abnormal_pred (bb))
949 #ifdef STACK_REGS
950 EXECUTE_IF_SET_IN_SPARSESET (pseudos_live, px)
951 lra_reg_info[px].no_stack_p = true;
952 for (px = FIRST_STACK_REG; px <= LAST_STACK_REG; px++)
953 make_hard_regno_born (px, false);
954 #endif
955 /* No need to record conflicts for call clobbered regs if we
956 have nonlocal labels around, as we don't ever try to
957 allocate such regs in this case. */
958 if (!cfun->has_nonlocal_label
959 && has_abnormal_call_or_eh_pred_edge_p (bb))
960 for (px = 0; px < FIRST_PSEUDO_REGISTER; px++)
961 if (call_used_regs[px]
962 #ifdef REAL_PIC_OFFSET_TABLE_REGNUM
963 /* We should create a conflict of PIC pseudo with PIC
964 hard reg as PIC hard reg can have a wrong value after
965 jump described by the abnormal edge. In this case we
966 can not allocate PIC hard reg to PIC pseudo as PIC
967 pseudo will also have a wrong value. */
968 || (px == REAL_PIC_OFFSET_TABLE_REGNUM
969 && pic_offset_table_rtx != NULL_RTX
970 && REGNO (pic_offset_table_rtx) >= FIRST_PSEUDO_REGISTER)
971 #endif
973 make_hard_regno_born (px, false);
976 bool live_change_p = false;
977 /* Check if bb border live info was changed. */
978 unsigned int live_pseudos_num = 0;
979 EXECUTE_IF_SET_IN_BITMAP (df_get_live_in (bb),
980 FIRST_PSEUDO_REGISTER, j, bi)
982 live_pseudos_num++;
983 if (! sparseset_bit_p (pseudos_live, j))
985 live_change_p = true;
986 if (lra_dump_file != NULL)
987 fprintf (lra_dump_file,
988 " r%d is removed as live at bb%d start\n", j, bb->index);
989 break;
992 if (! live_change_p
993 && sparseset_cardinality (pseudos_live) != live_pseudos_num)
995 live_change_p = true;
996 if (lra_dump_file != NULL)
997 EXECUTE_IF_SET_IN_SPARSESET (pseudos_live, j)
998 if (! bitmap_bit_p (df_get_live_in (bb), j))
999 fprintf (lra_dump_file,
1000 " r%d is added to live at bb%d start\n", j, bb->index);
1002 /* See if we'll need an increment at the end of this basic block.
1003 An increment is needed if the PSEUDOS_LIVE set is not empty,
1004 to make sure the finish points are set up correctly. */
1005 need_curr_point_incr = (sparseset_cardinality (pseudos_live) > 0);
1007 EXECUTE_IF_SET_IN_SPARSESET (pseudos_live, i)
1008 mark_pseudo_dead (i, curr_point);
1010 EXECUTE_IF_SET_IN_BITMAP (df_get_live_in (bb), FIRST_PSEUDO_REGISTER, j, bi)
1012 if (sparseset_cardinality (pseudos_live_through_calls) == 0)
1013 break;
1014 if (sparseset_bit_p (pseudos_live_through_calls, j))
1015 check_pseudos_live_through_calls (j);
1018 if (need_curr_point_incr)
1019 next_program_point (curr_point, freq);
1021 return live_change_p;
1024 /* Compress pseudo live ranges by removing program points where
1025 nothing happens. Complexity of many algorithms in LRA is linear
1026 function of program points number. To speed up the code we try to
1027 minimize the number of the program points here. */
1028 static void
1029 remove_some_program_points_and_update_live_ranges (void)
1031 unsigned i;
1032 int n, max_regno;
1033 int *map;
1034 lra_live_range_t r, prev_r, next_r;
1035 sbitmap born_or_dead, born, dead;
1036 sbitmap_iterator sbi;
1037 bool born_p, dead_p, prev_born_p, prev_dead_p;
1039 born = sbitmap_alloc (lra_live_max_point);
1040 dead = sbitmap_alloc (lra_live_max_point);
1041 bitmap_clear (born);
1042 bitmap_clear (dead);
1043 max_regno = max_reg_num ();
1044 for (i = FIRST_PSEUDO_REGISTER; i < (unsigned) max_regno; i++)
1046 for (r = lra_reg_info[i].live_ranges; r != NULL; r = r->next)
1048 lra_assert (r->start <= r->finish);
1049 bitmap_set_bit (born, r->start);
1050 bitmap_set_bit (dead, r->finish);
1053 born_or_dead = sbitmap_alloc (lra_live_max_point);
1054 bitmap_ior (born_or_dead, born, dead);
1055 map = XCNEWVEC (int, lra_live_max_point);
1056 n = -1;
1057 prev_born_p = prev_dead_p = false;
1058 EXECUTE_IF_SET_IN_BITMAP (born_or_dead, 0, i, sbi)
1060 born_p = bitmap_bit_p (born, i);
1061 dead_p = bitmap_bit_p (dead, i);
1062 if ((prev_born_p && ! prev_dead_p && born_p && ! dead_p)
1063 || (prev_dead_p && ! prev_born_p && dead_p && ! born_p))
1065 map[i] = n;
1066 lra_point_freq[n] = MAX (lra_point_freq[n], lra_point_freq[i]);
1068 else
1070 map[i] = ++n;
1071 lra_point_freq[n] = lra_point_freq[i];
1073 prev_born_p = born_p;
1074 prev_dead_p = dead_p;
1076 sbitmap_free (born_or_dead);
1077 sbitmap_free (born);
1078 sbitmap_free (dead);
1079 n++;
1080 if (lra_dump_file != NULL)
1081 fprintf (lra_dump_file, "Compressing live ranges: from %d to %d - %d%%\n",
1082 lra_live_max_point, n, 100 * n / lra_live_max_point);
1083 if (n < lra_live_max_point)
1085 lra_live_max_point = n;
1086 for (i = FIRST_PSEUDO_REGISTER; i < (unsigned) max_regno; i++)
1088 for (prev_r = NULL, r = lra_reg_info[i].live_ranges;
1089 r != NULL;
1090 r = next_r)
1092 next_r = r->next;
1093 r->start = map[r->start];
1094 r->finish = map[r->finish];
1095 if (prev_r == NULL || prev_r->start > r->finish + 1)
1097 prev_r = r;
1098 continue;
1100 prev_r->start = r->start;
1101 prev_r->next = next_r;
1102 delete r;
1106 free (map);
1109 /* Print live ranges R to file F. */
1110 void
1111 lra_print_live_range_list (FILE *f, lra_live_range_t r)
1113 for (; r != NULL; r = r->next)
1114 fprintf (f, " [%d..%d]", r->start, r->finish);
1115 fprintf (f, "\n");
1118 DEBUG_FUNCTION void
1119 debug (lra_live_range &ref)
1121 lra_print_live_range_list (stderr, &ref);
1124 DEBUG_FUNCTION void
1125 debug (lra_live_range *ptr)
1127 if (ptr)
1128 debug (*ptr);
1129 else
1130 fprintf (stderr, "<nil>\n");
1133 /* Print live ranges R to stderr. */
1134 void
1135 lra_debug_live_range_list (lra_live_range_t r)
1137 lra_print_live_range_list (stderr, r);
1140 /* Print live ranges of pseudo REGNO to file F. */
1141 static void
1142 print_pseudo_live_ranges (FILE *f, int regno)
1144 if (lra_reg_info[regno].live_ranges == NULL)
1145 return;
1146 fprintf (f, " r%d:", regno);
1147 lra_print_live_range_list (f, lra_reg_info[regno].live_ranges);
1150 /* Print live ranges of pseudo REGNO to stderr. */
1151 void
1152 lra_debug_pseudo_live_ranges (int regno)
1154 print_pseudo_live_ranges (stderr, regno);
1157 /* Print live ranges of all pseudos to file F. */
1158 static void
1159 print_live_ranges (FILE *f)
1161 int i, max_regno;
1163 max_regno = max_reg_num ();
1164 for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
1165 print_pseudo_live_ranges (f, i);
1168 /* Print live ranges of all pseudos to stderr. */
1169 void
1170 lra_debug_live_ranges (void)
1172 print_live_ranges (stderr);
1175 /* Compress pseudo live ranges. */
1176 static void
1177 compress_live_ranges (void)
1179 remove_some_program_points_and_update_live_ranges ();
1180 if (lra_dump_file != NULL)
1182 fprintf (lra_dump_file, "Ranges after the compression:\n");
1183 print_live_ranges (lra_dump_file);
1189 /* The number of the current live range pass. */
1190 int lra_live_range_iter;
1192 /* The function creates live ranges only for memory pseudos (or for
1193 all ones if ALL_P), set up CONFLICT_HARD_REGS for the pseudos. It
1194 also does dead insn elimination if DEAD_INSN_P and global live
1195 analysis only for pseudos and only if the pseudo live info was
1196 changed on a BB border. Return TRUE if the live info was
1197 changed. */
1198 static bool
1199 lra_create_live_ranges_1 (bool all_p, bool dead_insn_p)
1201 basic_block bb;
1202 int i, hard_regno, max_regno = max_reg_num ();
1203 int curr_point;
1204 bool bb_live_change_p, have_referenced_pseudos = false;
1206 timevar_push (TV_LRA_CREATE_LIVE_RANGES);
1208 complete_info_p = all_p;
1209 if (lra_dump_file != NULL)
1210 fprintf (lra_dump_file,
1211 "\n********** Pseudo live ranges #%d: **********\n\n",
1212 ++lra_live_range_iter);
1213 memset (lra_hard_reg_usage, 0, sizeof (lra_hard_reg_usage));
1214 for (i = 0; i < max_regno; i++)
1216 lra_reg_info[i].live_ranges = NULL;
1217 CLEAR_HARD_REG_SET (lra_reg_info[i].conflict_hard_regs);
1218 lra_reg_info[i].preferred_hard_regno1 = -1;
1219 lra_reg_info[i].preferred_hard_regno2 = -1;
1220 lra_reg_info[i].preferred_hard_regno_profit1 = 0;
1221 lra_reg_info[i].preferred_hard_regno_profit2 = 0;
1222 #ifdef STACK_REGS
1223 lra_reg_info[i].no_stack_p = false;
1224 #endif
1225 /* The biggest mode is already set but its value might be to
1226 conservative because of recent transformation. Here in this
1227 file we recalculate it again as it costs practically
1228 nothing. */
1229 if (regno_reg_rtx[i] != NULL_RTX)
1230 lra_reg_info[i].biggest_mode = GET_MODE (regno_reg_rtx[i]);
1231 else
1232 lra_reg_info[i].biggest_mode = VOIDmode;
1233 #ifdef ENABLE_CHECKING
1234 lra_reg_info[i].call_p = false;
1235 #endif
1236 if (i >= FIRST_PSEUDO_REGISTER
1237 && lra_reg_info[i].nrefs != 0)
1239 if ((hard_regno = reg_renumber[i]) >= 0)
1240 lra_hard_reg_usage[hard_regno] += lra_reg_info[i].freq;
1241 have_referenced_pseudos = true;
1244 lra_free_copies ();
1246 /* Under some circumstances, we can have functions without pseudo
1247 registers. For such functions, lra_live_max_point will be 0,
1248 see e.g. PR55604, and there's nothing more to do for us here. */
1249 if (! have_referenced_pseudos)
1251 timevar_pop (TV_LRA_CREATE_LIVE_RANGES);
1252 return false;
1255 pseudos_live = sparseset_alloc (max_regno);
1256 pseudos_live_through_calls = sparseset_alloc (max_regno);
1257 pseudos_live_through_setjumps = sparseset_alloc (max_regno);
1258 start_living = sparseset_alloc (max_regno);
1259 start_dying = sparseset_alloc (max_regno);
1260 dead_set = sparseset_alloc (max_regno);
1261 unused_set = sparseset_alloc (max_regno);
1262 curr_point = 0;
1263 point_freq_vec.create (get_max_uid () * 2);
1264 lra_point_freq = point_freq_vec.address ();
1265 int *post_order_rev_cfg = XNEWVEC (int, last_basic_block_for_fn (cfun));
1266 int n_blocks_inverted = inverted_post_order_compute (post_order_rev_cfg);
1267 lra_assert (n_blocks_inverted == n_basic_blocks_for_fn (cfun));
1268 bb_live_change_p = false;
1269 for (i = n_blocks_inverted - 1; i >= 0; --i)
1271 bb = BASIC_BLOCK_FOR_FN (cfun, post_order_rev_cfg[i]);
1272 if (bb == EXIT_BLOCK_PTR_FOR_FN (cfun) || bb
1273 == ENTRY_BLOCK_PTR_FOR_FN (cfun))
1274 continue;
1275 if (process_bb_lives (bb, curr_point, dead_insn_p))
1276 bb_live_change_p = true;
1278 if (bb_live_change_p)
1280 /* We need to clear pseudo live info as some pseudos can
1281 disappear, e.g. pseudos with used equivalences. */
1282 FOR_EACH_BB_FN (bb, cfun)
1284 bitmap_clear_range (df_get_live_in (bb), FIRST_PSEUDO_REGISTER,
1285 max_regno - FIRST_PSEUDO_REGISTER);
1286 bitmap_clear_range (df_get_live_out (bb), FIRST_PSEUDO_REGISTER,
1287 max_regno - FIRST_PSEUDO_REGISTER);
1289 /* As we did not change CFG since LRA start we can use
1290 DF-infrastructure solver to solve live data flow problem. */
1291 df_simple_dataflow
1292 (DF_BACKWARD, NULL, live_con_fun_0, live_con_fun_n,
1293 live_trans_fun, &all_blocks,
1294 df_get_postorder (DF_BACKWARD), df_get_n_blocks (DF_BACKWARD));
1295 if (lra_dump_file != NULL)
1297 fprintf (lra_dump_file,
1298 "Global pseudo live data have been updated:\n");
1299 basic_block bb;
1300 FOR_EACH_BB_FN (bb, cfun)
1302 bb_data_t bb_info = get_bb_data (bb);
1303 bitmap bb_livein = df_get_live_in (bb);
1304 bitmap bb_liveout = df_get_live_out (bb);
1306 fprintf (lra_dump_file, "\nBB %d:\n", bb->index);
1307 lra_dump_bitmap_with_title (" gen:",
1308 &bb_info->gen_pseudos, bb->index);
1309 lra_dump_bitmap_with_title (" killed:",
1310 &bb_info->killed_pseudos, bb->index);
1311 lra_dump_bitmap_with_title (" livein:", bb_livein, bb->index);
1312 lra_dump_bitmap_with_title (" liveout:", bb_liveout, bb->index);
1316 free (post_order_rev_cfg);
1317 lra_live_max_point = curr_point;
1318 if (lra_dump_file != NULL)
1319 print_live_ranges (lra_dump_file);
1320 /* Clean up. */
1321 sparseset_free (unused_set);
1322 sparseset_free (dead_set);
1323 sparseset_free (start_dying);
1324 sparseset_free (start_living);
1325 sparseset_free (pseudos_live_through_calls);
1326 sparseset_free (pseudos_live_through_setjumps);
1327 sparseset_free (pseudos_live);
1328 compress_live_ranges ();
1329 timevar_pop (TV_LRA_CREATE_LIVE_RANGES);
1330 return bb_live_change_p;
1333 /* The main entry function creates live-ranges and other live info
1334 necessary for the assignment sub-pass. It uses
1335 lra_creates_live_ranges_1 -- so read comments for the
1336 function. */
1337 void
1338 lra_create_live_ranges (bool all_p, bool dead_insn_p)
1340 if (! lra_create_live_ranges_1 (all_p, dead_insn_p))
1341 return;
1342 if (lra_dump_file != NULL)
1343 fprintf (lra_dump_file, "Live info was changed -- recalculate it\n");
1344 /* Live info was changed on a bb border. It means that some info,
1345 e.g. about conflict regs, calls crossed, and live ranges may be
1346 wrong. We need this info for allocation. So recalculate it
1347 again but without removing dead insns which can change live info
1348 again. Repetitive live range calculations are expensive therefore
1349 we stop here as we already have correct info although some
1350 improvement in rare cases could be possible on this sub-pass if
1351 we do dead insn elimination again (still the improvement may
1352 happen later). */
1353 lra_clear_live_ranges ();
1354 bool res = lra_create_live_ranges_1 (all_p, false);
1355 lra_assert (! res);
1358 /* Finish all live ranges. */
1359 void
1360 lra_clear_live_ranges (void)
1362 int i;
1364 for (i = 0; i < max_reg_num (); i++)
1365 free_live_range_list (lra_reg_info[i].live_ranges);
1366 point_freq_vec.release ();
1369 /* Initialize live ranges data once per function. */
1370 void
1371 lra_live_ranges_init (void)
1373 bitmap_initialize (&temp_bitmap, &reg_obstack);
1374 initiate_live_solver ();
1377 /* Finish live ranges data once per function. */
1378 void
1379 lra_live_ranges_finish (void)
1381 finish_live_solver ();
1382 bitmap_clear (&temp_bitmap);
1383 lra_live_range_pool.release ();