2015-06-11 Paul Thomas <pault@gcc.gnu.org>
[official-gcc.git] / gcc / lra-lives.c
blob66baaddda1c3f9c0ce29d936aebd4c40e822952f
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 "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 "input.h"
40 #include "function.h"
41 #include "symtab.h"
42 #include "flags.h"
43 #include "alias.h"
44 #include "tree.h"
45 #include "expmed.h"
46 #include "dojump.h"
47 #include "explow.h"
48 #include "calls.h"
49 #include "emit-rtl.h"
50 #include "varasm.h"
51 #include "stmt.h"
52 #include "expr.h"
53 #include "predict.h"
54 #include "dominance.h"
55 #include "cfg.h"
56 #include "cfganal.h"
57 #include "basic-block.h"
58 #include "except.h"
59 #include "df.h"
60 #include "ira.h"
61 #include "sparseset.h"
62 #include "lra-int.h"
64 /* Program points are enumerated by numbers from range
65 0..LRA_LIVE_MAX_POINT-1. There are approximately two times more
66 program points than insns. Program points are places in the
67 program where liveness info can be changed. In most general case
68 (there are more complicated cases too) some program points
69 correspond to places where input operand dies and other ones
70 correspond to places where output operands are born. */
71 int lra_live_max_point;
73 /* Accumulated execution frequency of all references for each hard
74 register. */
75 int lra_hard_reg_usage[FIRST_PSEUDO_REGISTER];
77 /* A global flag whose true value says to build live ranges for all
78 pseudos, otherwise the live ranges only for pseudos got memory is
79 build. True value means also building copies and setting up hard
80 register preferences. The complete info is necessary only for the
81 assignment pass. The complete info is not needed for the
82 coalescing and spill passes. */
83 static bool complete_info_p;
85 /* Pseudos live at current point in the RTL scan. */
86 static sparseset pseudos_live;
88 /* Pseudos probably living through calls and setjumps. As setjump is
89 a call too, if a bit in PSEUDOS_LIVE_THROUGH_SETJUMPS is set up
90 then the corresponding bit in PSEUDOS_LIVE_THROUGH_CALLS is set up
91 too. These data are necessary for cases when only one subreg of a
92 multi-reg pseudo is set up after a call. So we decide it is
93 probably live when traversing bb backward. We are sure about
94 living when we see its usage or definition of the pseudo. */
95 static sparseset pseudos_live_through_calls;
96 static sparseset pseudos_live_through_setjumps;
98 /* Set of hard regs (except eliminable ones) currently live. */
99 static HARD_REG_SET hard_regs_live;
101 /* Set of pseudos and hard registers start living/dying in the current
102 insn. These sets are used to update REG_DEAD and REG_UNUSED notes
103 in the insn. */
104 static sparseset start_living, start_dying;
106 /* Set of pseudos and hard regs dead and unused in the current
107 insn. */
108 static sparseset unused_set, dead_set;
110 /* Bitmap used for holding intermediate bitmap operation results. */
111 static bitmap_head temp_bitmap;
113 /* Pool for pseudo live ranges. */
114 pool_allocator <lra_live_range> lra_live_range::pool ("live ranges", 100);
116 /* Free live range list LR. */
117 static void
118 free_live_range_list (lra_live_range_t lr)
120 lra_live_range_t next;
122 while (lr != NULL)
124 next = lr->next;
125 delete lr;
126 lr = next;
130 /* Create and return pseudo live range with given attributes. */
131 static lra_live_range_t
132 create_live_range (int regno, int start, int finish, lra_live_range_t next)
134 lra_live_range_t p = new lra_live_range;
135 p->regno = regno;
136 p->start = start;
137 p->finish = finish;
138 p->next = next;
139 return p;
142 /* Copy live range R and return the result. */
143 static lra_live_range_t
144 copy_live_range (lra_live_range_t r)
146 return new lra_live_range (*r);
149 /* Copy live range list given by its head R and return the result. */
150 lra_live_range_t
151 lra_copy_live_range_list (lra_live_range_t r)
153 lra_live_range_t p, first, *chain;
155 first = NULL;
156 for (chain = &first; r != NULL; r = r->next)
158 p = copy_live_range (r);
159 *chain = p;
160 chain = &p->next;
162 return first;
165 /* Merge *non-intersected* ranges R1 and R2 and returns the result.
166 The function maintains the order of ranges and tries to minimize
167 size of the result range list. Ranges R1 and R2 may not be used
168 after the call. */
169 lra_live_range_t
170 lra_merge_live_ranges (lra_live_range_t r1, lra_live_range_t r2)
172 lra_live_range_t first, last;
174 if (r1 == NULL)
175 return r2;
176 if (r2 == NULL)
177 return r1;
178 for (first = last = NULL; r1 != NULL && r2 != NULL;)
180 if (r1->start < r2->start)
181 std::swap (r1, r2);
183 if (r1->start == r2->finish + 1)
185 /* Joint ranges: merge r1 and r2 into r1. */
186 r1->start = r2->start;
187 lra_live_range_t temp = r2;
188 r2 = r2->next;
189 delete temp;
191 else
193 gcc_assert (r2->finish + 1 < r1->start);
194 /* Add r1 to the result. */
195 if (first == NULL)
196 first = last = r1;
197 else
199 last->next = r1;
200 last = r1;
202 r1 = r1->next;
205 if (r1 != NULL)
207 if (first == NULL)
208 first = r1;
209 else
210 last->next = r1;
212 else
214 lra_assert (r2 != NULL);
215 if (first == NULL)
216 first = r2;
217 else
218 last->next = r2;
220 return first;
223 /* Return TRUE if live ranges R1 and R2 intersect. */
224 bool
225 lra_intersected_live_ranges_p (lra_live_range_t r1, lra_live_range_t r2)
227 /* Remember the live ranges are always kept ordered. */
228 while (r1 != NULL && r2 != NULL)
230 if (r1->start > r2->finish)
231 r1 = r1->next;
232 else if (r2->start > r1->finish)
233 r2 = r2->next;
234 else
235 return true;
237 return false;
240 /* The function processing birth of hard register REGNO. It updates
241 living hard regs, START_LIVING, and conflict hard regs for living
242 pseudos. Conflict hard regs for the pic pseudo is not updated if
243 REGNO is REAL_PIC_OFFSET_TABLE_REGNUM and CHECK_PIC_PSEUDO_P is
244 true. */
245 static void
246 make_hard_regno_born (int regno, bool check_pic_pseudo_p ATTRIBUTE_UNUSED)
248 unsigned int i;
250 lra_assert (regno < FIRST_PSEUDO_REGISTER);
251 if (TEST_HARD_REG_BIT (hard_regs_live, regno))
252 return;
253 SET_HARD_REG_BIT (hard_regs_live, regno);
254 sparseset_set_bit (start_living, regno);
255 EXECUTE_IF_SET_IN_SPARSESET (pseudos_live, i)
256 #ifdef REAL_PIC_OFFSET_TABLE_REGNUM
257 if (! check_pic_pseudo_p
258 || regno != REAL_PIC_OFFSET_TABLE_REGNUM
259 || pic_offset_table_rtx == NULL
260 || i != REGNO (pic_offset_table_rtx))
261 #endif
262 SET_HARD_REG_BIT (lra_reg_info[i].conflict_hard_regs, regno);
265 /* Process the death of hard register REGNO. This updates
266 hard_regs_live and START_DYING. */
267 static void
268 make_hard_regno_dead (int regno)
270 lra_assert (regno < FIRST_PSEUDO_REGISTER);
271 if (! TEST_HARD_REG_BIT (hard_regs_live, regno))
272 return;
273 sparseset_set_bit (start_dying, regno);
274 CLEAR_HARD_REG_BIT (hard_regs_live, regno);
277 /* Mark pseudo REGNO as living at program point POINT, update conflicting
278 hard registers of the pseudo and START_LIVING, and start a new live
279 range for the pseudo corresponding to REGNO if it is necessary. */
280 static void
281 mark_pseudo_live (int regno, int point)
283 lra_live_range_t p;
285 lra_assert (regno >= FIRST_PSEUDO_REGISTER);
286 lra_assert (! sparseset_bit_p (pseudos_live, regno));
287 sparseset_set_bit (pseudos_live, regno);
288 IOR_HARD_REG_SET (lra_reg_info[regno].conflict_hard_regs, hard_regs_live);
290 if ((complete_info_p || lra_get_regno_hard_regno (regno) < 0)
291 && ((p = lra_reg_info[regno].live_ranges) == NULL
292 || (p->finish != point && p->finish + 1 != point)))
293 lra_reg_info[regno].live_ranges
294 = create_live_range (regno, point, -1, p);
295 sparseset_set_bit (start_living, regno);
298 /* Mark pseudo REGNO as not living at program point POINT and update
299 START_DYING.
300 This finishes the current live range for the pseudo corresponding
301 to REGNO. */
302 static void
303 mark_pseudo_dead (int regno, int point)
305 lra_live_range_t p;
307 lra_assert (regno >= FIRST_PSEUDO_REGISTER);
308 lra_assert (sparseset_bit_p (pseudos_live, regno));
309 sparseset_clear_bit (pseudos_live, regno);
310 sparseset_set_bit (start_dying, regno);
311 if (complete_info_p || lra_get_regno_hard_regno (regno) < 0)
313 p = lra_reg_info[regno].live_ranges;
314 lra_assert (p != NULL);
315 p->finish = point;
319 /* The corresponding bitmaps of BB currently being processed. */
320 static bitmap bb_killed_pseudos, bb_gen_pseudos;
322 /* Mark register REGNO (pseudo or hard register) in MODE as live at
323 program point POINT. Update BB_GEN_PSEUDOS.
324 Return TRUE if the liveness tracking sets were modified, or FALSE
325 if nothing changed. */
326 static bool
327 mark_regno_live (int regno, machine_mode mode, int point)
329 int last;
330 bool changed = false;
332 if (regno < FIRST_PSEUDO_REGISTER)
334 for (last = regno + hard_regno_nregs[regno][mode];
335 regno < last;
336 regno++)
337 make_hard_regno_born (regno, false);
339 else
341 if (! sparseset_bit_p (pseudos_live, regno))
343 mark_pseudo_live (regno, point);
344 changed = true;
346 bitmap_set_bit (bb_gen_pseudos, regno);
348 return changed;
352 /* Mark register REGNO in MODE as dead at program point POINT. Update
353 BB_GEN_PSEUDOS and BB_KILLED_PSEUDOS. Return TRUE if the liveness
354 tracking sets were modified, or FALSE if nothing changed. */
355 static bool
356 mark_regno_dead (int regno, machine_mode mode, int point)
358 int last;
359 bool changed = false;
361 if (regno < FIRST_PSEUDO_REGISTER)
363 for (last = regno + hard_regno_nregs[regno][mode];
364 regno < last;
365 regno++)
366 make_hard_regno_dead (regno);
368 else
370 if (sparseset_bit_p (pseudos_live, regno))
372 mark_pseudo_dead (regno, point);
373 changed = true;
375 bitmap_clear_bit (bb_gen_pseudos, regno);
376 bitmap_set_bit (bb_killed_pseudos, regno);
378 return changed;
383 /* This page contains code for making global live analysis of pseudos.
384 The code works only when pseudo live info is changed on a BB
385 border. That might be a consequence of some global transformations
386 in LRA, e.g. PIC pseudo reuse or rematerialization. */
388 /* Structure describing local BB data used for pseudo
389 live-analysis. */
390 struct bb_data_pseudos
392 /* Basic block about which the below data are. */
393 basic_block bb;
394 bitmap_head killed_pseudos; /* pseudos killed in the BB. */
395 bitmap_head gen_pseudos; /* pseudos generated in the BB. */
398 /* Array for all BB data. Indexed by the corresponding BB index. */
399 typedef struct bb_data_pseudos *bb_data_t;
401 /* All basic block data are referred through the following array. */
402 static bb_data_t bb_data;
404 /* Two small functions for access to the bb data. */
405 static inline bb_data_t
406 get_bb_data (basic_block bb)
408 return &bb_data[(bb)->index];
411 static inline bb_data_t
412 get_bb_data_by_index (int index)
414 return &bb_data[index];
417 /* Bitmap with all hard regs. */
418 static bitmap_head all_hard_regs_bitmap;
420 /* The transfer function used by the DF equation solver to propagate
421 live info through block with BB_INDEX according to the following
422 equation:
424 bb.livein = (bb.liveout - bb.kill) OR bb.gen
426 static bool
427 live_trans_fun (int bb_index)
429 basic_block bb = get_bb_data_by_index (bb_index)->bb;
430 bitmap bb_liveout = df_get_live_out (bb);
431 bitmap bb_livein = df_get_live_in (bb);
432 bb_data_t bb_info = get_bb_data (bb);
434 bitmap_and_compl (&temp_bitmap, bb_liveout, &all_hard_regs_bitmap);
435 return bitmap_ior_and_compl (bb_livein, &bb_info->gen_pseudos,
436 &temp_bitmap, &bb_info->killed_pseudos);
439 /* The confluence function used by the DF equation solver to set up
440 live info for a block BB without predecessor. */
441 static void
442 live_con_fun_0 (basic_block bb)
444 bitmap_and_into (df_get_live_out (bb), &all_hard_regs_bitmap);
447 /* The confluence function used by the DF equation solver to propagate
448 live info from successor to predecessor on edge E according to the
449 following equation:
451 bb.liveout = 0 for entry block | OR (livein of successors)
453 static bool
454 live_con_fun_n (edge e)
456 basic_block bb = e->src;
457 basic_block dest = e->dest;
458 bitmap bb_liveout = df_get_live_out (bb);
459 bitmap dest_livein = df_get_live_in (dest);
461 return bitmap_ior_and_compl_into (bb_liveout,
462 dest_livein, &all_hard_regs_bitmap);
465 /* Indexes of all function blocks. */
466 static bitmap_head all_blocks;
468 /* Allocate and initialize data needed for global pseudo live
469 analysis. */
470 static void
471 initiate_live_solver (void)
473 bitmap_initialize (&all_hard_regs_bitmap, &reg_obstack);
474 bitmap_set_range (&all_hard_regs_bitmap, 0, FIRST_PSEUDO_REGISTER);
475 bb_data = XNEWVEC (struct bb_data_pseudos, last_basic_block_for_fn (cfun));
476 bitmap_initialize (&all_blocks, &reg_obstack);
478 basic_block bb;
479 FOR_ALL_BB_FN (bb, cfun)
481 bb_data_t bb_info = get_bb_data (bb);
482 bb_info->bb = bb;
483 bitmap_initialize (&bb_info->killed_pseudos, &reg_obstack);
484 bitmap_initialize (&bb_info->gen_pseudos, &reg_obstack);
485 bitmap_set_bit (&all_blocks, bb->index);
489 /* Free all data needed for global pseudo live analysis. */
490 static void
491 finish_live_solver (void)
493 basic_block bb;
495 bitmap_clear (&all_blocks);
496 FOR_ALL_BB_FN (bb, cfun)
498 bb_data_t bb_info = get_bb_data (bb);
499 bitmap_clear (&bb_info->killed_pseudos);
500 bitmap_clear (&bb_info->gen_pseudos);
502 free (bb_data);
503 bitmap_clear (&all_hard_regs_bitmap);
508 /* Insn currently scanned. */
509 static rtx_insn *curr_insn;
510 /* The insn data. */
511 static lra_insn_recog_data_t curr_id;
512 /* The insn static data. */
513 static struct lra_static_insn_data *curr_static_id;
515 /* Return true when one of the predecessor edges of BB is marked with
516 EDGE_ABNORMAL_CALL or EDGE_EH. */
517 static bool
518 bb_has_abnormal_call_pred (basic_block bb)
520 edge e;
521 edge_iterator ei;
523 FOR_EACH_EDGE (e, ei, bb->preds)
525 if (e->flags & (EDGE_ABNORMAL_CALL | EDGE_EH))
526 return true;
528 return false;
531 /* Vec containing execution frequencies of program points. */
532 static vec<int> point_freq_vec;
534 /* The start of the above vector elements. */
535 int *lra_point_freq;
537 /* Increment the current program point POINT to the next point which has
538 execution frequency FREQ. */
539 static void
540 next_program_point (int &point, int freq)
542 point_freq_vec.safe_push (freq);
543 lra_point_freq = point_freq_vec.address ();
544 point++;
547 /* Update the preference of HARD_REGNO for pseudo REGNO by PROFIT. */
548 void
549 lra_setup_reload_pseudo_preferenced_hard_reg (int regno,
550 int hard_regno, int profit)
552 lra_assert (regno >= lra_constraint_new_regno_start);
553 if (lra_reg_info[regno].preferred_hard_regno1 == hard_regno)
554 lra_reg_info[regno].preferred_hard_regno_profit1 += profit;
555 else if (lra_reg_info[regno].preferred_hard_regno2 == hard_regno)
556 lra_reg_info[regno].preferred_hard_regno_profit2 += profit;
557 else if (lra_reg_info[regno].preferred_hard_regno1 < 0)
559 lra_reg_info[regno].preferred_hard_regno1 = hard_regno;
560 lra_reg_info[regno].preferred_hard_regno_profit1 = profit;
562 else if (lra_reg_info[regno].preferred_hard_regno2 < 0
563 || profit > lra_reg_info[regno].preferred_hard_regno_profit2)
565 lra_reg_info[regno].preferred_hard_regno2 = hard_regno;
566 lra_reg_info[regno].preferred_hard_regno_profit2 = profit;
568 else
569 return;
570 /* Keep the 1st hard regno as more profitable. */
571 if (lra_reg_info[regno].preferred_hard_regno1 >= 0
572 && lra_reg_info[regno].preferred_hard_regno2 >= 0
573 && (lra_reg_info[regno].preferred_hard_regno_profit2
574 > lra_reg_info[regno].preferred_hard_regno_profit1))
576 int temp;
578 temp = lra_reg_info[regno].preferred_hard_regno1;
579 lra_reg_info[regno].preferred_hard_regno1
580 = lra_reg_info[regno].preferred_hard_regno2;
581 lra_reg_info[regno].preferred_hard_regno2 = temp;
582 temp = lra_reg_info[regno].preferred_hard_regno_profit1;
583 lra_reg_info[regno].preferred_hard_regno_profit1
584 = lra_reg_info[regno].preferred_hard_regno_profit2;
585 lra_reg_info[regno].preferred_hard_regno_profit2 = temp;
587 if (lra_dump_file != NULL)
589 if ((hard_regno = lra_reg_info[regno].preferred_hard_regno1) >= 0)
590 fprintf (lra_dump_file,
591 " Hard reg %d is preferable by r%d with profit %d\n",
592 hard_regno, regno,
593 lra_reg_info[regno].preferred_hard_regno_profit1);
594 if ((hard_regno = lra_reg_info[regno].preferred_hard_regno2) >= 0)
595 fprintf (lra_dump_file,
596 " Hard reg %d is preferable by r%d with profit %d\n",
597 hard_regno, regno,
598 lra_reg_info[regno].preferred_hard_regno_profit2);
602 /* Check that REGNO living through calls and setjumps, set up conflict
603 regs, and clear corresponding bits in PSEUDOS_LIVE_THROUGH_CALLS and
604 PSEUDOS_LIVE_THROUGH_SETJUMPS. */
605 static inline void
606 check_pseudos_live_through_calls (int regno)
608 int hr;
610 if (! sparseset_bit_p (pseudos_live_through_calls, regno))
611 return;
612 sparseset_clear_bit (pseudos_live_through_calls, regno);
613 IOR_HARD_REG_SET (lra_reg_info[regno].conflict_hard_regs,
614 call_used_reg_set);
616 for (hr = 0; hr < FIRST_PSEUDO_REGISTER; hr++)
617 if (HARD_REGNO_CALL_PART_CLOBBERED (hr, PSEUDO_REGNO_MODE (regno)))
618 SET_HARD_REG_BIT (lra_reg_info[regno].conflict_hard_regs, hr);
619 #ifdef ENABLE_CHECKING
620 lra_reg_info[regno].call_p = true;
621 #endif
622 if (! sparseset_bit_p (pseudos_live_through_setjumps, regno))
623 return;
624 sparseset_clear_bit (pseudos_live_through_setjumps, regno);
625 /* Don't allocate pseudos that cross setjmps or any call, if this
626 function receives a nonlocal goto. */
627 SET_HARD_REG_SET (lra_reg_info[regno].conflict_hard_regs);
630 /* Process insns of the basic block BB to update pseudo live ranges,
631 pseudo hard register conflicts, and insn notes. We do it on
632 backward scan of BB insns. CURR_POINT is the program point where
633 BB ends. The function updates this counter and returns in
634 CURR_POINT the program point where BB starts. The function also
635 does local live info updates and can delete the dead insns if
636 DEAD_INSN_P. It returns true if pseudo live info was
637 changed at the BB start. */
638 static bool
639 process_bb_lives (basic_block bb, int &curr_point, bool dead_insn_p)
641 int i, regno, freq;
642 unsigned int j;
643 bitmap_iterator bi;
644 bitmap reg_live_out;
645 unsigned int px;
646 rtx_insn *next;
647 rtx link, *link_loc;
648 bool need_curr_point_incr;
650 reg_live_out = df_get_live_out (bb);
651 sparseset_clear (pseudos_live);
652 sparseset_clear (pseudos_live_through_calls);
653 sparseset_clear (pseudos_live_through_setjumps);
654 REG_SET_TO_HARD_REG_SET (hard_regs_live, reg_live_out);
655 AND_COMPL_HARD_REG_SET (hard_regs_live, eliminable_regset);
656 EXECUTE_IF_SET_IN_BITMAP (reg_live_out, FIRST_PSEUDO_REGISTER, j, bi)
657 mark_pseudo_live (j, curr_point);
659 bb_gen_pseudos = &get_bb_data (bb)->gen_pseudos;
660 bb_killed_pseudos = &get_bb_data (bb)->killed_pseudos;
661 bitmap_clear (bb_gen_pseudos);
662 bitmap_clear (bb_killed_pseudos);
663 freq = REG_FREQ_FROM_BB (bb);
665 if (lra_dump_file != NULL)
666 fprintf (lra_dump_file, " BB %d\n", bb->index);
668 /* Scan the code of this basic block, noting which pseudos and hard
669 regs are born or die.
671 Note that this loop treats uninitialized values as live until the
672 beginning of the block. For example, if an instruction uses
673 (reg:DI foo), and only (subreg:SI (reg:DI foo) 0) is ever set,
674 FOO will remain live until the beginning of the block. Likewise
675 if FOO is not set at all. This is unnecessarily pessimistic, but
676 it probably doesn't matter much in practice. */
677 FOR_BB_INSNS_REVERSE_SAFE (bb, curr_insn, next)
679 bool call_p;
680 int dst_regno, src_regno;
681 rtx set;
682 struct lra_insn_reg *reg;
684 if (!NONDEBUG_INSN_P (curr_insn))
685 continue;
687 curr_id = lra_get_insn_recog_data (curr_insn);
688 curr_static_id = curr_id->insn_static_data;
689 if (lra_dump_file != NULL)
690 fprintf (lra_dump_file, " Insn %u: point = %d\n",
691 INSN_UID (curr_insn), curr_point);
693 set = single_set (curr_insn);
695 if (dead_insn_p && set != NULL_RTX
696 && REG_P (SET_DEST (set)) && REGNO (SET_DEST (set)) >= FIRST_PSEUDO_REGISTER
697 && find_reg_note (curr_insn, REG_EH_REGION, NULL_RTX) == NULL_RTX
698 && ! may_trap_p (PATTERN (curr_insn))
699 /* Don't do premature remove of pic offset pseudo as we can
700 start to use it after some reload generation. */
701 && (pic_offset_table_rtx == NULL_RTX
702 || pic_offset_table_rtx != SET_DEST (set)))
704 bool remove_p = true;
706 for (reg = curr_id->regs; reg != NULL; reg = reg->next)
707 if (reg->type != OP_IN && sparseset_bit_p (pseudos_live, reg->regno))
709 remove_p = false;
710 break;
712 for (reg = curr_static_id->hard_regs; reg != NULL; reg = reg->next)
713 if (reg->type != OP_IN)
715 remove_p = false;
716 break;
718 if (remove_p && ! volatile_refs_p (PATTERN (curr_insn)))
720 dst_regno = REGNO (SET_DEST (set));
721 if (lra_dump_file != NULL)
722 fprintf (lra_dump_file, " Deleting dead insn %u\n",
723 INSN_UID (curr_insn));
724 lra_set_insn_deleted (curr_insn);
725 if (lra_reg_info[dst_regno].nrefs == 0)
727 /* There might be some debug insns with the pseudo. */
728 unsigned int uid;
729 rtx_insn *insn;
731 bitmap_copy (&temp_bitmap, &lra_reg_info[dst_regno].insn_bitmap);
732 EXECUTE_IF_SET_IN_BITMAP (&temp_bitmap, 0, uid, bi)
734 insn = lra_insn_recog_data[uid]->insn;
735 lra_substitute_pseudo_within_insn (insn, dst_regno,
736 SET_SRC (set));
737 lra_update_insn_regno_info (insn);
740 continue;
744 /* Update max ref width and hard reg usage. */
745 for (reg = curr_id->regs; reg != NULL; reg = reg->next)
746 if (reg->regno >= FIRST_PSEUDO_REGISTER
747 && (GET_MODE_SIZE (reg->biggest_mode)
748 > GET_MODE_SIZE (lra_reg_info[reg->regno].biggest_mode)))
749 lra_reg_info[reg->regno].biggest_mode = reg->biggest_mode;
750 else if (reg->regno < FIRST_PSEUDO_REGISTER)
751 lra_hard_reg_usage[reg->regno] += freq;
753 call_p = CALL_P (curr_insn);
754 if (complete_info_p
755 && set != NULL_RTX
756 && REG_P (SET_DEST (set)) && REG_P (SET_SRC (set))
757 /* Check that source regno does not conflict with
758 destination regno to exclude most impossible
759 preferences. */
760 && ((((src_regno = REGNO (SET_SRC (set))) >= FIRST_PSEUDO_REGISTER
761 && ! sparseset_bit_p (pseudos_live, src_regno))
762 || (src_regno < FIRST_PSEUDO_REGISTER
763 && ! TEST_HARD_REG_BIT (hard_regs_live, src_regno)))
764 /* It might be 'inheritance pseudo <- reload pseudo'. */
765 || (src_regno >= lra_constraint_new_regno_start
766 && ((int) REGNO (SET_DEST (set))
767 >= lra_constraint_new_regno_start)
768 /* Remember to skip special cases where src/dest regnos are
769 the same, e.g. insn SET pattern has matching constraints
770 like =r,0. */
771 && src_regno != (int) REGNO (SET_DEST (set)))))
773 int hard_regno = -1, regno = -1;
775 dst_regno = REGNO (SET_DEST (set));
776 if (dst_regno >= lra_constraint_new_regno_start
777 && src_regno >= lra_constraint_new_regno_start)
778 lra_create_copy (dst_regno, src_regno, freq);
779 else if (dst_regno >= lra_constraint_new_regno_start)
781 if ((hard_regno = src_regno) >= FIRST_PSEUDO_REGISTER)
782 hard_regno = reg_renumber[src_regno];
783 regno = dst_regno;
785 else if (src_regno >= lra_constraint_new_regno_start)
787 if ((hard_regno = dst_regno) >= FIRST_PSEUDO_REGISTER)
788 hard_regno = reg_renumber[dst_regno];
789 regno = src_regno;
791 if (regno >= 0 && hard_regno >= 0)
792 lra_setup_reload_pseudo_preferenced_hard_reg
793 (regno, hard_regno, freq);
796 sparseset_clear (start_living);
798 /* Try to avoid unnecessary program point increments, this saves
799 a lot of time in remove_some_program_points_and_update_live_ranges.
800 We only need an increment if something becomes live or dies at this
801 program point. */
802 need_curr_point_incr = false;
804 /* Mark each defined value as live. We need to do this for
805 unused values because they still conflict with quantities
806 that are live at the time of the definition. */
807 for (reg = curr_id->regs; reg != NULL; reg = reg->next)
808 if (reg->type != OP_IN)
810 need_curr_point_incr
811 |= mark_regno_live (reg->regno, reg->biggest_mode,
812 curr_point);
813 check_pseudos_live_through_calls (reg->regno);
816 for (reg = curr_static_id->hard_regs; reg != NULL; reg = reg->next)
817 if (reg->type != OP_IN)
818 make_hard_regno_born (reg->regno, false);
820 sparseset_copy (unused_set, start_living);
822 sparseset_clear (start_dying);
824 /* See which defined values die here. */
825 for (reg = curr_id->regs; reg != NULL; reg = reg->next)
826 if (reg->type == OP_OUT && ! reg->early_clobber && ! reg->subreg_p)
827 need_curr_point_incr
828 |= mark_regno_dead (reg->regno, reg->biggest_mode,
829 curr_point);
831 for (reg = curr_static_id->hard_regs; reg != NULL; reg = reg->next)
832 if (reg->type == OP_OUT && ! reg->early_clobber && ! reg->subreg_p)
833 make_hard_regno_dead (reg->regno);
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 make_hard_regno_born (regno, true);
885 sparseset_and_compl (dead_set, start_living, start_dying);
887 /* Mark early clobber outputs dead. */
888 for (reg = curr_id->regs; reg != NULL; reg = reg->next)
889 if (reg->type == OP_OUT && reg->early_clobber && ! reg->subreg_p)
890 need_curr_point_incr
891 |= mark_regno_dead (reg->regno, reg->biggest_mode,
892 curr_point);
894 for (reg = curr_static_id->hard_regs; reg != NULL; reg = reg->next)
895 if (reg->type == OP_OUT && reg->early_clobber && ! reg->subreg_p)
896 make_hard_regno_dead (reg->regno);
898 if (need_curr_point_incr)
899 next_program_point (curr_point, freq);
901 /* Update notes. */
902 for (link_loc = &REG_NOTES (curr_insn); (link = *link_loc) != NULL_RTX;)
904 if (REG_NOTE_KIND (link) != REG_DEAD
905 && REG_NOTE_KIND (link) != REG_UNUSED)
907 else if (REG_P (XEXP (link, 0)))
909 regno = REGNO (XEXP (link, 0));
910 if ((REG_NOTE_KIND (link) == REG_DEAD
911 && ! sparseset_bit_p (dead_set, regno))
912 || (REG_NOTE_KIND (link) == REG_UNUSED
913 && ! sparseset_bit_p (unused_set, regno)))
915 *link_loc = XEXP (link, 1);
916 continue;
918 if (REG_NOTE_KIND (link) == REG_DEAD)
919 sparseset_clear_bit (dead_set, regno);
920 else if (REG_NOTE_KIND (link) == REG_UNUSED)
921 sparseset_clear_bit (unused_set, regno);
923 link_loc = &XEXP (link, 1);
925 EXECUTE_IF_SET_IN_SPARSESET (dead_set, j)
926 add_reg_note (curr_insn, REG_DEAD, regno_reg_rtx[j]);
927 EXECUTE_IF_SET_IN_SPARSESET (unused_set, j)
928 add_reg_note (curr_insn, REG_UNUSED, regno_reg_rtx[j]);
931 if (bb_has_eh_pred (bb))
932 for (j = 0; ; ++j)
934 unsigned int regno = EH_RETURN_DATA_REGNO (j);
936 if (regno == INVALID_REGNUM)
937 break;
938 make_hard_regno_born (regno, false);
941 /* Pseudos can't go in stack regs at the start of a basic block that
942 is reached by an abnormal edge. Likewise for call clobbered regs,
943 because caller-save, fixup_abnormal_edges and possibly the table
944 driven EH machinery are not quite ready to handle such pseudos
945 live across such edges. */
946 if (bb_has_abnormal_pred (bb))
948 #ifdef STACK_REGS
949 EXECUTE_IF_SET_IN_SPARSESET (pseudos_live, px)
950 lra_reg_info[px].no_stack_p = true;
951 for (px = FIRST_STACK_REG; px <= LAST_STACK_REG; px++)
952 make_hard_regno_born (px, false);
953 #endif
954 /* No need to record conflicts for call clobbered regs if we
955 have nonlocal labels around, as we don't ever try to
956 allocate such regs in this case. */
957 if (!cfun->has_nonlocal_label && bb_has_abnormal_call_pred (bb))
958 for (px = 0; px < FIRST_PSEUDO_REGISTER; px++)
959 if (call_used_regs[px])
960 make_hard_regno_born (px, false);
963 bool live_change_p = false;
964 /* Check if bb border live info was changed. */
965 unsigned int live_pseudos_num = 0;
966 EXECUTE_IF_SET_IN_BITMAP (df_get_live_in (bb),
967 FIRST_PSEUDO_REGISTER, j, bi)
969 live_pseudos_num++;
970 if (! sparseset_bit_p (pseudos_live, j))
972 live_change_p = true;
973 if (lra_dump_file != NULL)
974 fprintf (lra_dump_file,
975 " r%d is removed as live at bb%d start\n", j, bb->index);
976 break;
979 if (! live_change_p
980 && sparseset_cardinality (pseudos_live) != live_pseudos_num)
982 live_change_p = true;
983 if (lra_dump_file != NULL)
984 EXECUTE_IF_SET_IN_SPARSESET (pseudos_live, j)
985 if (! bitmap_bit_p (df_get_live_in (bb), j))
986 fprintf (lra_dump_file,
987 " r%d is added to live at bb%d start\n", j, bb->index);
989 /* See if we'll need an increment at the end of this basic block.
990 An increment is needed if the PSEUDOS_LIVE set is not empty,
991 to make sure the finish points are set up correctly. */
992 need_curr_point_incr = (sparseset_cardinality (pseudos_live) > 0);
994 EXECUTE_IF_SET_IN_SPARSESET (pseudos_live, i)
995 mark_pseudo_dead (i, curr_point);
997 EXECUTE_IF_SET_IN_BITMAP (df_get_live_in (bb), FIRST_PSEUDO_REGISTER, j, bi)
999 if (sparseset_cardinality (pseudos_live_through_calls) == 0)
1000 break;
1001 if (sparseset_bit_p (pseudos_live_through_calls, j))
1002 check_pseudos_live_through_calls (j);
1005 if (need_curr_point_incr)
1006 next_program_point (curr_point, freq);
1008 return live_change_p;
1011 /* Compress pseudo live ranges by removing program points where
1012 nothing happens. Complexity of many algorithms in LRA is linear
1013 function of program points number. To speed up the code we try to
1014 minimize the number of the program points here. */
1015 static void
1016 remove_some_program_points_and_update_live_ranges (void)
1018 unsigned i;
1019 int n, max_regno;
1020 int *map;
1021 lra_live_range_t r, prev_r, next_r;
1022 sbitmap born_or_dead, born, dead;
1023 sbitmap_iterator sbi;
1024 bool born_p, dead_p, prev_born_p, prev_dead_p;
1026 born = sbitmap_alloc (lra_live_max_point);
1027 dead = sbitmap_alloc (lra_live_max_point);
1028 bitmap_clear (born);
1029 bitmap_clear (dead);
1030 max_regno = max_reg_num ();
1031 for (i = FIRST_PSEUDO_REGISTER; i < (unsigned) max_regno; i++)
1033 for (r = lra_reg_info[i].live_ranges; r != NULL; r = r->next)
1035 lra_assert (r->start <= r->finish);
1036 bitmap_set_bit (born, r->start);
1037 bitmap_set_bit (dead, r->finish);
1040 born_or_dead = sbitmap_alloc (lra_live_max_point);
1041 bitmap_ior (born_or_dead, born, dead);
1042 map = XCNEWVEC (int, lra_live_max_point);
1043 n = -1;
1044 prev_born_p = prev_dead_p = false;
1045 EXECUTE_IF_SET_IN_BITMAP (born_or_dead, 0, i, sbi)
1047 born_p = bitmap_bit_p (born, i);
1048 dead_p = bitmap_bit_p (dead, i);
1049 if ((prev_born_p && ! prev_dead_p && born_p && ! dead_p)
1050 || (prev_dead_p && ! prev_born_p && dead_p && ! born_p))
1052 map[i] = n;
1053 lra_point_freq[n] = MAX (lra_point_freq[n], lra_point_freq[i]);
1055 else
1057 map[i] = ++n;
1058 lra_point_freq[n] = lra_point_freq[i];
1060 prev_born_p = born_p;
1061 prev_dead_p = dead_p;
1063 sbitmap_free (born_or_dead);
1064 sbitmap_free (born);
1065 sbitmap_free (dead);
1066 n++;
1067 if (lra_dump_file != NULL)
1068 fprintf (lra_dump_file, "Compressing live ranges: from %d to %d - %d%%\n",
1069 lra_live_max_point, n, 100 * n / lra_live_max_point);
1070 if (n < lra_live_max_point)
1072 lra_live_max_point = n;
1073 for (i = FIRST_PSEUDO_REGISTER; i < (unsigned) max_regno; i++)
1075 for (prev_r = NULL, r = lra_reg_info[i].live_ranges;
1076 r != NULL;
1077 r = next_r)
1079 next_r = r->next;
1080 r->start = map[r->start];
1081 r->finish = map[r->finish];
1082 if (prev_r == NULL || prev_r->start > r->finish + 1)
1084 prev_r = r;
1085 continue;
1087 prev_r->start = r->start;
1088 prev_r->next = next_r;
1089 delete r;
1093 free (map);
1096 /* Print live ranges R to file F. */
1097 void
1098 lra_print_live_range_list (FILE *f, lra_live_range_t r)
1100 for (; r != NULL; r = r->next)
1101 fprintf (f, " [%d..%d]", r->start, r->finish);
1102 fprintf (f, "\n");
1105 DEBUG_FUNCTION void
1106 debug (lra_live_range &ref)
1108 lra_print_live_range_list (stderr, &ref);
1111 DEBUG_FUNCTION void
1112 debug (lra_live_range *ptr)
1114 if (ptr)
1115 debug (*ptr);
1116 else
1117 fprintf (stderr, "<nil>\n");
1120 /* Print live ranges R to stderr. */
1121 void
1122 lra_debug_live_range_list (lra_live_range_t r)
1124 lra_print_live_range_list (stderr, r);
1127 /* Print live ranges of pseudo REGNO to file F. */
1128 static void
1129 print_pseudo_live_ranges (FILE *f, int regno)
1131 if (lra_reg_info[regno].live_ranges == NULL)
1132 return;
1133 fprintf (f, " r%d:", regno);
1134 lra_print_live_range_list (f, lra_reg_info[regno].live_ranges);
1137 /* Print live ranges of pseudo REGNO to stderr. */
1138 void
1139 lra_debug_pseudo_live_ranges (int regno)
1141 print_pseudo_live_ranges (stderr, regno);
1144 /* Print live ranges of all pseudos to file F. */
1145 static void
1146 print_live_ranges (FILE *f)
1148 int i, max_regno;
1150 max_regno = max_reg_num ();
1151 for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
1152 print_pseudo_live_ranges (f, i);
1155 /* Print live ranges of all pseudos to stderr. */
1156 void
1157 lra_debug_live_ranges (void)
1159 print_live_ranges (stderr);
1162 /* Compress pseudo live ranges. */
1163 static void
1164 compress_live_ranges (void)
1166 remove_some_program_points_and_update_live_ranges ();
1167 if (lra_dump_file != NULL)
1169 fprintf (lra_dump_file, "Ranges after the compression:\n");
1170 print_live_ranges (lra_dump_file);
1176 /* The number of the current live range pass. */
1177 int lra_live_range_iter;
1179 /* The function creates live ranges only for memory pseudos (or for
1180 all ones if ALL_P), set up CONFLICT_HARD_REGS for the pseudos. It
1181 also does dead insn elimination if DEAD_INSN_P and global live
1182 analysis only for pseudos and only if the pseudo live info was
1183 changed on a BB border. Return TRUE if the live info was
1184 changed. */
1185 static bool
1186 lra_create_live_ranges_1 (bool all_p, bool dead_insn_p)
1188 basic_block bb;
1189 int i, hard_regno, max_regno = max_reg_num ();
1190 int curr_point;
1191 bool bb_live_change_p, have_referenced_pseudos = false;
1193 timevar_push (TV_LRA_CREATE_LIVE_RANGES);
1195 complete_info_p = all_p;
1196 if (lra_dump_file != NULL)
1197 fprintf (lra_dump_file,
1198 "\n********** Pseudo live ranges #%d: **********\n\n",
1199 ++lra_live_range_iter);
1200 memset (lra_hard_reg_usage, 0, sizeof (lra_hard_reg_usage));
1201 for (i = 0; i < max_regno; i++)
1203 lra_reg_info[i].live_ranges = NULL;
1204 CLEAR_HARD_REG_SET (lra_reg_info[i].conflict_hard_regs);
1205 lra_reg_info[i].preferred_hard_regno1 = -1;
1206 lra_reg_info[i].preferred_hard_regno2 = -1;
1207 lra_reg_info[i].preferred_hard_regno_profit1 = 0;
1208 lra_reg_info[i].preferred_hard_regno_profit2 = 0;
1209 #ifdef STACK_REGS
1210 lra_reg_info[i].no_stack_p = false;
1211 #endif
1212 /* The biggest mode is already set but its value might be to
1213 conservative because of recent transformation. Here in this
1214 file we recalculate it again as it costs practically
1215 nothing. */
1216 if (regno_reg_rtx[i] != NULL_RTX)
1217 lra_reg_info[i].biggest_mode = GET_MODE (regno_reg_rtx[i]);
1218 else
1219 lra_reg_info[i].biggest_mode = VOIDmode;
1220 #ifdef ENABLE_CHECKING
1221 lra_reg_info[i].call_p = false;
1222 #endif
1223 if (i >= FIRST_PSEUDO_REGISTER
1224 && lra_reg_info[i].nrefs != 0)
1226 if ((hard_regno = reg_renumber[i]) >= 0)
1227 lra_hard_reg_usage[hard_regno] += lra_reg_info[i].freq;
1228 have_referenced_pseudos = true;
1231 lra_free_copies ();
1233 /* Under some circumstances, we can have functions without pseudo
1234 registers. For such functions, lra_live_max_point will be 0,
1235 see e.g. PR55604, and there's nothing more to do for us here. */
1236 if (! have_referenced_pseudos)
1238 timevar_pop (TV_LRA_CREATE_LIVE_RANGES);
1239 return false;
1242 pseudos_live = sparseset_alloc (max_regno);
1243 pseudos_live_through_calls = sparseset_alloc (max_regno);
1244 pseudos_live_through_setjumps = sparseset_alloc (max_regno);
1245 start_living = sparseset_alloc (max_regno);
1246 start_dying = sparseset_alloc (max_regno);
1247 dead_set = sparseset_alloc (max_regno);
1248 unused_set = sparseset_alloc (max_regno);
1249 curr_point = 0;
1250 point_freq_vec.create (get_max_uid () * 2);
1251 lra_point_freq = point_freq_vec.address ();
1252 int *post_order_rev_cfg = XNEWVEC (int, last_basic_block_for_fn (cfun));
1253 int n_blocks_inverted = inverted_post_order_compute (post_order_rev_cfg);
1254 lra_assert (n_blocks_inverted == n_basic_blocks_for_fn (cfun));
1255 bb_live_change_p = false;
1256 for (i = n_blocks_inverted - 1; i >= 0; --i)
1258 bb = BASIC_BLOCK_FOR_FN (cfun, post_order_rev_cfg[i]);
1259 if (bb == EXIT_BLOCK_PTR_FOR_FN (cfun) || bb
1260 == ENTRY_BLOCK_PTR_FOR_FN (cfun))
1261 continue;
1262 if (process_bb_lives (bb, curr_point, dead_insn_p))
1263 bb_live_change_p = true;
1265 if (bb_live_change_p)
1267 /* We need to clear pseudo live info as some pseudos can
1268 disappear, e.g. pseudos with used equivalences. */
1269 FOR_EACH_BB_FN (bb, cfun)
1271 bitmap_clear_range (df_get_live_in (bb), FIRST_PSEUDO_REGISTER,
1272 max_regno - FIRST_PSEUDO_REGISTER);
1273 bitmap_clear_range (df_get_live_out (bb), FIRST_PSEUDO_REGISTER,
1274 max_regno - FIRST_PSEUDO_REGISTER);
1276 /* As we did not change CFG since LRA start we can use
1277 DF-infrastructure solver to solve live data flow problem. */
1278 df_simple_dataflow
1279 (DF_BACKWARD, NULL, live_con_fun_0, live_con_fun_n,
1280 live_trans_fun, &all_blocks,
1281 df_get_postorder (DF_BACKWARD), df_get_n_blocks (DF_BACKWARD));
1282 if (lra_dump_file != NULL)
1284 fprintf (lra_dump_file,
1285 "Global pseudo live data have been updated:\n");
1286 basic_block bb;
1287 FOR_EACH_BB_FN (bb, cfun)
1289 bb_data_t bb_info = get_bb_data (bb);
1290 bitmap bb_livein = df_get_live_in (bb);
1291 bitmap bb_liveout = df_get_live_out (bb);
1293 fprintf (lra_dump_file, "\nBB %d:\n", bb->index);
1294 lra_dump_bitmap_with_title (" gen:",
1295 &bb_info->gen_pseudos, bb->index);
1296 lra_dump_bitmap_with_title (" killed:",
1297 &bb_info->killed_pseudos, bb->index);
1298 lra_dump_bitmap_with_title (" livein:", bb_livein, bb->index);
1299 lra_dump_bitmap_with_title (" liveout:", bb_liveout, bb->index);
1303 free (post_order_rev_cfg);
1304 lra_live_max_point = curr_point;
1305 if (lra_dump_file != NULL)
1306 print_live_ranges (lra_dump_file);
1307 /* Clean up. */
1308 sparseset_free (unused_set);
1309 sparseset_free (dead_set);
1310 sparseset_free (start_dying);
1311 sparseset_free (start_living);
1312 sparseset_free (pseudos_live_through_calls);
1313 sparseset_free (pseudos_live_through_setjumps);
1314 sparseset_free (pseudos_live);
1315 compress_live_ranges ();
1316 timevar_pop (TV_LRA_CREATE_LIVE_RANGES);
1317 return bb_live_change_p;
1320 /* The main entry function creates live-ranges and other live info
1321 necessary for the assignment sub-pass. It uses
1322 lra_creates_live_ranges_1 -- so read comments for the
1323 function. */
1324 void
1325 lra_create_live_ranges (bool all_p, bool dead_insn_p)
1327 if (! lra_create_live_ranges_1 (all_p, dead_insn_p))
1328 return;
1329 if (lra_dump_file != NULL)
1330 fprintf (lra_dump_file, "Live info was changed -- recalculate it\n");
1331 /* Live info was changed on a bb border. It means that some info,
1332 e.g. about conflict regs, calls crossed, and live ranges may be
1333 wrong. We need this info for allocation. So recalculate it
1334 again but without removing dead insns which can change live info
1335 again. Repetitive live range calculations are expensive therefore
1336 we stop here as we already have correct info although some
1337 improvement in rare cases could be possible on this sub-pass if
1338 we do dead insn elimination again (still the improvement may
1339 happen later). */
1340 lra_clear_live_ranges ();
1341 bool res = lra_create_live_ranges_1 (all_p, false);
1342 lra_assert (! res);
1345 /* Finish all live ranges. */
1346 void
1347 lra_clear_live_ranges (void)
1349 int i;
1351 for (i = 0; i < max_reg_num (); i++)
1352 free_live_range_list (lra_reg_info[i].live_ranges);
1353 point_freq_vec.release ();
1356 /* Initialize live ranges data once per function. */
1357 void
1358 lra_live_ranges_init (void)
1360 bitmap_initialize (&temp_bitmap, &reg_obstack);
1361 initiate_live_solver ();
1364 /* Finish live ranges data once per function. */
1365 void
1366 lra_live_ranges_finish (void)
1368 finish_live_solver ();
1369 bitmap_clear (&temp_bitmap);
1370 lra_live_range::pool.release ();