* gcc.dg/20020919-1.c: Use _ARCH_PPC64 to test for -mpowerpc64.
[official-gcc.git] / gcc / lra-lives.c
blob50d3969ea3bde8f70754b1c3159582e0cd342417
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 "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 "symtab.h"
46 #include "flags.h"
47 #include "statistics.h"
48 #include "double-int.h"
49 #include "real.h"
50 #include "fixed-value.h"
51 #include "alias.h"
52 #include "wide-int.h"
53 #include "inchash.h"
54 #include "tree.h"
55 #include "expmed.h"
56 #include "dojump.h"
57 #include "explow.h"
58 #include "calls.h"
59 #include "emit-rtl.h"
60 #include "varasm.h"
61 #include "stmt.h"
62 #include "expr.h"
63 #include "predict.h"
64 #include "dominance.h"
65 #include "cfg.h"
66 #include "cfganal.h"
67 #include "basic-block.h"
68 #include "except.h"
69 #include "df.h"
70 #include "ira.h"
71 #include "sparseset.h"
72 #include "lra-int.h"
74 /* Program points are enumerated by numbers from range
75 0..LRA_LIVE_MAX_POINT-1. There are approximately two times more
76 program points than insns. Program points are places in the
77 program where liveness info can be changed. In most general case
78 (there are more complicated cases too) some program points
79 correspond to places where input operand dies and other ones
80 correspond to places where output operands are born. */
81 int lra_live_max_point;
83 /* Accumulated execution frequency of all references for each hard
84 register. */
85 int lra_hard_reg_usage[FIRST_PSEUDO_REGISTER];
87 /* A global flag whose true value says to build live ranges for all
88 pseudos, otherwise the live ranges only for pseudos got memory is
89 build. True value means also building copies and setting up hard
90 register preferences. The complete info is necessary only for the
91 assignment pass. The complete info is not needed for the
92 coalescing and spill passes. */
93 static bool complete_info_p;
95 /* Pseudos live at current point in the RTL scan. */
96 static sparseset pseudos_live;
98 /* Pseudos probably living through calls and setjumps. As setjump is
99 a call too, if a bit in PSEUDOS_LIVE_THROUGH_SETJUMPS is set up
100 then the corresponding bit in PSEUDOS_LIVE_THROUGH_CALLS is set up
101 too. These data are necessary for cases when only one subreg of a
102 multi-reg pseudo is set up after a call. So we decide it is
103 probably live when traversing bb backward. We are sure about
104 living when we see its usage or definition of the pseudo. */
105 static sparseset pseudos_live_through_calls;
106 static sparseset pseudos_live_through_setjumps;
108 /* Set of hard regs (except eliminable ones) currently live. */
109 static HARD_REG_SET hard_regs_live;
111 /* Set of pseudos and hard registers start living/dying in the current
112 insn. These sets are used to update REG_DEAD and REG_UNUSED notes
113 in the insn. */
114 static sparseset start_living, start_dying;
116 /* Set of pseudos and hard regs dead and unused in the current
117 insn. */
118 static sparseset unused_set, dead_set;
120 /* Bitmap used for holding intermediate bitmap operation results. */
121 static bitmap_head temp_bitmap;
123 /* Pool for pseudo live ranges. */
124 static alloc_pool live_range_pool;
126 /* Free live range LR. */
127 static void
128 free_live_range (lra_live_range_t lr)
130 pool_free (live_range_pool, lr);
133 /* Free live range list LR. */
134 static void
135 free_live_range_list (lra_live_range_t lr)
137 lra_live_range_t next;
139 while (lr != NULL)
141 next = lr->next;
142 free_live_range (lr);
143 lr = next;
147 /* Create and return pseudo live range with given attributes. */
148 static lra_live_range_t
149 create_live_range (int regno, int start, int finish, lra_live_range_t next)
151 lra_live_range_t p;
153 p = (lra_live_range_t) pool_alloc (live_range_pool);
154 p->regno = regno;
155 p->start = start;
156 p->finish = finish;
157 p->next = next;
158 return p;
161 /* Copy live range R and return the result. */
162 static lra_live_range_t
163 copy_live_range (lra_live_range_t r)
165 lra_live_range_t p;
167 p = (lra_live_range_t) pool_alloc (live_range_pool);
168 *p = *r;
169 return p;
172 /* Copy live range list given by its head R and return the result. */
173 lra_live_range_t
174 lra_copy_live_range_list (lra_live_range_t r)
176 lra_live_range_t p, first, *chain;
178 first = NULL;
179 for (chain = &first; r != NULL; r = r->next)
181 p = copy_live_range (r);
182 *chain = p;
183 chain = &p->next;
185 return first;
188 /* Merge *non-intersected* ranges R1 and R2 and returns the result.
189 The function maintains the order of ranges and tries to minimize
190 size of the result range list. Ranges R1 and R2 may not be used
191 after the call. */
192 lra_live_range_t
193 lra_merge_live_ranges (lra_live_range_t r1, lra_live_range_t r2)
195 lra_live_range_t first, last, temp;
197 if (r1 == NULL)
198 return r2;
199 if (r2 == NULL)
200 return r1;
201 for (first = last = NULL; r1 != NULL && r2 != NULL;)
203 if (r1->start < r2->start)
205 temp = r1;
206 r1 = r2;
207 r2 = temp;
209 if (r1->start == r2->finish + 1)
211 /* Joint ranges: merge r1 and r2 into r1. */
212 r1->start = r2->start;
213 temp = r2;
214 r2 = r2->next;
215 pool_free (live_range_pool, temp);
217 else
219 gcc_assert (r2->finish + 1 < r1->start);
220 /* Add r1 to the result. */
221 if (first == NULL)
222 first = last = r1;
223 else
225 last->next = r1;
226 last = r1;
228 r1 = r1->next;
231 if (r1 != NULL)
233 if (first == NULL)
234 first = r1;
235 else
236 last->next = r1;
238 else
240 lra_assert (r2 != NULL);
241 if (first == NULL)
242 first = r2;
243 else
244 last->next = r2;
246 return first;
249 /* Return TRUE if live ranges R1 and R2 intersect. */
250 bool
251 lra_intersected_live_ranges_p (lra_live_range_t r1, lra_live_range_t r2)
253 /* Remember the live ranges are always kept ordered. */
254 while (r1 != NULL && r2 != NULL)
256 if (r1->start > r2->finish)
257 r1 = r1->next;
258 else if (r2->start > r1->finish)
259 r2 = r2->next;
260 else
261 return true;
263 return false;
266 /* The function processing birth of hard register REGNO. It updates
267 living hard regs, conflict hard regs for living pseudos, and
268 START_LIVING. */
269 static void
270 make_hard_regno_born (int regno)
272 unsigned int i;
274 lra_assert (regno < FIRST_PSEUDO_REGISTER);
275 if (TEST_HARD_REG_BIT (hard_regs_live, regno))
276 return;
277 SET_HARD_REG_BIT (hard_regs_live, regno);
278 sparseset_set_bit (start_living, regno);
279 EXECUTE_IF_SET_IN_SPARSESET (pseudos_live, i)
280 SET_HARD_REG_BIT (lra_reg_info[i].conflict_hard_regs, regno);
283 /* Process the death of hard register REGNO. This updates
284 hard_regs_live and START_DYING. */
285 static void
286 make_hard_regno_dead (int regno)
288 lra_assert (regno < FIRST_PSEUDO_REGISTER);
289 if (! TEST_HARD_REG_BIT (hard_regs_live, regno))
290 return;
291 sparseset_set_bit (start_dying, regno);
292 CLEAR_HARD_REG_BIT (hard_regs_live, regno);
295 /* Mark pseudo REGNO as living at program point POINT, update conflicting
296 hard registers of the pseudo and START_LIVING, and start a new live
297 range for the pseudo corresponding to REGNO if it is necessary. */
298 static void
299 mark_pseudo_live (int regno, int point)
301 lra_live_range_t p;
303 lra_assert (regno >= FIRST_PSEUDO_REGISTER);
304 lra_assert (! sparseset_bit_p (pseudos_live, regno));
305 sparseset_set_bit (pseudos_live, regno);
306 IOR_HARD_REG_SET (lra_reg_info[regno].conflict_hard_regs, hard_regs_live);
308 if ((complete_info_p || lra_get_regno_hard_regno (regno) < 0)
309 && ((p = lra_reg_info[regno].live_ranges) == NULL
310 || (p->finish != point && p->finish + 1 != point)))
311 lra_reg_info[regno].live_ranges
312 = create_live_range (regno, point, -1, p);
313 sparseset_set_bit (start_living, regno);
316 /* Mark pseudo REGNO as not living at program point POINT and update
317 START_DYING.
318 This finishes the current live range for the pseudo corresponding
319 to REGNO. */
320 static void
321 mark_pseudo_dead (int regno, int point)
323 lra_live_range_t p;
325 lra_assert (regno >= FIRST_PSEUDO_REGISTER);
326 lra_assert (sparseset_bit_p (pseudos_live, regno));
327 sparseset_clear_bit (pseudos_live, regno);
328 sparseset_set_bit (start_dying, regno);
329 if (complete_info_p || lra_get_regno_hard_regno (regno) < 0)
331 p = lra_reg_info[regno].live_ranges;
332 lra_assert (p != NULL);
333 p->finish = point;
337 /* The corresponding bitmaps of BB currently being processed. */
338 static bitmap bb_killed_pseudos, bb_gen_pseudos;
340 /* Mark register REGNO (pseudo or hard register) in MODE as live at
341 program point POINT. Update BB_GEN_PSEUDOS.
342 Return TRUE if the liveness tracking sets were modified, or FALSE
343 if nothing changed. */
344 static bool
345 mark_regno_live (int regno, machine_mode mode, int point)
347 int last;
348 bool changed = false;
350 if (regno < FIRST_PSEUDO_REGISTER)
352 for (last = regno + hard_regno_nregs[regno][mode];
353 regno < last;
354 regno++)
355 make_hard_regno_born (regno);
357 else
359 if (! sparseset_bit_p (pseudos_live, regno))
361 mark_pseudo_live (regno, point);
362 changed = true;
364 bitmap_set_bit (bb_gen_pseudos, regno);
366 return changed;
370 /* Mark register REGNO in MODE as dead at program point POINT. Update
371 BB_GEN_PSEUDOS and BB_KILLED_PSEUDOS. Return TRUE if the liveness
372 tracking sets were modified, or FALSE if nothing changed. */
373 static bool
374 mark_regno_dead (int regno, machine_mode mode, int point)
376 int last;
377 bool changed = false;
379 if (regno < FIRST_PSEUDO_REGISTER)
381 for (last = regno + hard_regno_nregs[regno][mode];
382 regno < last;
383 regno++)
384 make_hard_regno_dead (regno);
386 else
388 if (sparseset_bit_p (pseudos_live, regno))
390 mark_pseudo_dead (regno, point);
391 changed = true;
393 bitmap_clear_bit (bb_gen_pseudos, regno);
394 bitmap_set_bit (bb_killed_pseudos, regno);
396 return changed;
401 /* This page contains code for making global live analysis of pseudos.
402 The code works only when pseudo live info is changed on a BB
403 border. That might be a consequence of some global transformations
404 in LRA, e.g. PIC pseudo reuse or rematerialization. */
406 /* Structure describing local BB data used for pseudo
407 live-analysis. */
408 struct bb_data_pseudos
410 /* Basic block about which the below data are. */
411 basic_block bb;
412 bitmap_head killed_pseudos; /* pseudos killed in the BB. */
413 bitmap_head gen_pseudos; /* pseudos generated in the BB. */
416 /* Array for all BB data. Indexed by the corresponding BB index. */
417 typedef struct bb_data_pseudos *bb_data_t;
419 /* All basic block data are referred through the following array. */
420 static bb_data_t bb_data;
422 /* Two small functions for access to the bb data. */
423 static inline bb_data_t
424 get_bb_data (basic_block bb)
426 return &bb_data[(bb)->index];
429 static inline bb_data_t
430 get_bb_data_by_index (int index)
432 return &bb_data[index];
435 /* Bitmap with all hard regs. */
436 static bitmap_head all_hard_regs_bitmap;
438 /* The transfer function used by the DF equation solver to propagate
439 live info through block with BB_INDEX according to the following
440 equation:
442 bb.livein = (bb.liveout - bb.kill) OR bb.gen
444 static bool
445 live_trans_fun (int bb_index)
447 basic_block bb = get_bb_data_by_index (bb_index)->bb;
448 bitmap bb_liveout = df_get_live_out (bb);
449 bitmap bb_livein = df_get_live_in (bb);
450 bb_data_t bb_info = get_bb_data (bb);
452 bitmap_and_compl (&temp_bitmap, bb_liveout, &all_hard_regs_bitmap);
453 return bitmap_ior_and_compl (bb_livein, &bb_info->gen_pseudos,
454 &temp_bitmap, &bb_info->killed_pseudos);
457 /* The confluence function used by the DF equation solver to set up
458 live info for a block BB without predecessor. */
459 static void
460 live_con_fun_0 (basic_block bb)
462 bitmap_and_into (df_get_live_out (bb), &all_hard_regs_bitmap);
465 /* The confluence function used by the DF equation solver to propagate
466 live info from successor to predecessor on edge E according to the
467 following equation:
469 bb.liveout = 0 for entry block | OR (livein of successors)
471 static bool
472 live_con_fun_n (edge e)
474 basic_block bb = e->src;
475 basic_block dest = e->dest;
476 bitmap bb_liveout = df_get_live_out (bb);
477 bitmap dest_livein = df_get_live_in (dest);
479 return bitmap_ior_and_compl_into (bb_liveout,
480 dest_livein, &all_hard_regs_bitmap);
483 /* Indexes of all function blocks. */
484 static bitmap_head all_blocks;
486 /* Allocate and initialize data needed for global pseudo live
487 analysis. */
488 static void
489 initiate_live_solver (void)
491 bitmap_initialize (&all_hard_regs_bitmap, &reg_obstack);
492 bitmap_set_range (&all_hard_regs_bitmap, 0, FIRST_PSEUDO_REGISTER);
493 bb_data = XNEWVEC (struct bb_data_pseudos, last_basic_block_for_fn (cfun));
494 bitmap_initialize (&all_blocks, &reg_obstack);
496 basic_block bb;
497 FOR_ALL_BB_FN (bb, cfun)
499 bb_data_t bb_info = get_bb_data (bb);
500 bb_info->bb = bb;
501 bitmap_initialize (&bb_info->killed_pseudos, &reg_obstack);
502 bitmap_initialize (&bb_info->gen_pseudos, &reg_obstack);
503 bitmap_set_bit (&all_blocks, bb->index);
507 /* Free all data needed for global pseudo live analysis. */
508 static void
509 finish_live_solver (void)
511 basic_block bb;
513 bitmap_clear (&all_blocks);
514 FOR_ALL_BB_FN (bb, cfun)
516 bb_data_t bb_info = get_bb_data (bb);
517 bitmap_clear (&bb_info->killed_pseudos);
518 bitmap_clear (&bb_info->gen_pseudos);
520 free (bb_data);
521 bitmap_clear (&all_hard_regs_bitmap);
526 /* Insn currently scanned. */
527 static rtx_insn *curr_insn;
528 /* The insn data. */
529 static lra_insn_recog_data_t curr_id;
530 /* The insn static data. */
531 static struct lra_static_insn_data *curr_static_id;
533 /* Return true when one of the predecessor edges of BB is marked with
534 EDGE_ABNORMAL_CALL or EDGE_EH. */
535 static bool
536 bb_has_abnormal_call_pred (basic_block bb)
538 edge e;
539 edge_iterator ei;
541 FOR_EACH_EDGE (e, ei, bb->preds)
543 if (e->flags & (EDGE_ABNORMAL_CALL | EDGE_EH))
544 return true;
546 return false;
549 /* Vec containing execution frequencies of program points. */
550 static vec<int> point_freq_vec;
552 /* The start of the above vector elements. */
553 int *lra_point_freq;
555 /* Increment the current program point POINT to the next point which has
556 execution frequency FREQ. */
557 static void
558 next_program_point (int &point, int freq)
560 point_freq_vec.safe_push (freq);
561 lra_point_freq = point_freq_vec.address ();
562 point++;
565 /* Update the preference of HARD_REGNO for pseudo REGNO by PROFIT. */
566 void
567 lra_setup_reload_pseudo_preferenced_hard_reg (int regno,
568 int hard_regno, int profit)
570 lra_assert (regno >= lra_constraint_new_regno_start);
571 if (lra_reg_info[regno].preferred_hard_regno1 == hard_regno)
572 lra_reg_info[regno].preferred_hard_regno_profit1 += profit;
573 else if (lra_reg_info[regno].preferred_hard_regno2 == hard_regno)
574 lra_reg_info[regno].preferred_hard_regno_profit2 += profit;
575 else if (lra_reg_info[regno].preferred_hard_regno1 < 0)
577 lra_reg_info[regno].preferred_hard_regno1 = hard_regno;
578 lra_reg_info[regno].preferred_hard_regno_profit1 = profit;
580 else if (lra_reg_info[regno].preferred_hard_regno2 < 0
581 || profit > lra_reg_info[regno].preferred_hard_regno_profit2)
583 lra_reg_info[regno].preferred_hard_regno2 = hard_regno;
584 lra_reg_info[regno].preferred_hard_regno_profit2 = profit;
586 else
587 return;
588 /* Keep the 1st hard regno as more profitable. */
589 if (lra_reg_info[regno].preferred_hard_regno1 >= 0
590 && lra_reg_info[regno].preferred_hard_regno2 >= 0
591 && (lra_reg_info[regno].preferred_hard_regno_profit2
592 > lra_reg_info[regno].preferred_hard_regno_profit1))
594 int temp;
596 temp = lra_reg_info[regno].preferred_hard_regno1;
597 lra_reg_info[regno].preferred_hard_regno1
598 = lra_reg_info[regno].preferred_hard_regno2;
599 lra_reg_info[regno].preferred_hard_regno2 = temp;
600 temp = lra_reg_info[regno].preferred_hard_regno_profit1;
601 lra_reg_info[regno].preferred_hard_regno_profit1
602 = lra_reg_info[regno].preferred_hard_regno_profit2;
603 lra_reg_info[regno].preferred_hard_regno_profit2 = temp;
605 if (lra_dump_file != NULL)
607 if ((hard_regno = lra_reg_info[regno].preferred_hard_regno1) >= 0)
608 fprintf (lra_dump_file,
609 " Hard reg %d is preferable by r%d with profit %d\n",
610 hard_regno, regno,
611 lra_reg_info[regno].preferred_hard_regno_profit1);
612 if ((hard_regno = lra_reg_info[regno].preferred_hard_regno2) >= 0)
613 fprintf (lra_dump_file,
614 " Hard reg %d is preferable by r%d with profit %d\n",
615 hard_regno, regno,
616 lra_reg_info[regno].preferred_hard_regno_profit2);
620 /* Check that REGNO living through calls and setjumps, set up conflict
621 regs, and clear corresponding bits in PSEUDOS_LIVE_THROUGH_CALLS and
622 PSEUDOS_LIVE_THROUGH_SETJUMPS. */
623 static inline void
624 check_pseudos_live_through_calls (int regno)
626 int hr;
628 if (! sparseset_bit_p (pseudos_live_through_calls, regno))
629 return;
630 sparseset_clear_bit (pseudos_live_through_calls, regno);
631 IOR_HARD_REG_SET (lra_reg_info[regno].conflict_hard_regs,
632 call_used_reg_set);
634 for (hr = 0; hr < FIRST_PSEUDO_REGISTER; hr++)
635 if (HARD_REGNO_CALL_PART_CLOBBERED (hr, PSEUDO_REGNO_MODE (regno)))
636 SET_HARD_REG_BIT (lra_reg_info[regno].conflict_hard_regs, hr);
637 #ifdef ENABLE_CHECKING
638 lra_reg_info[regno].call_p = true;
639 #endif
640 if (! sparseset_bit_p (pseudos_live_through_setjumps, regno))
641 return;
642 sparseset_clear_bit (pseudos_live_through_setjumps, regno);
643 /* Don't allocate pseudos that cross setjmps or any call, if this
644 function receives a nonlocal goto. */
645 SET_HARD_REG_SET (lra_reg_info[regno].conflict_hard_regs);
648 /* Process insns of the basic block BB to update pseudo live ranges,
649 pseudo hard register conflicts, and insn notes. We do it on
650 backward scan of BB insns. CURR_POINT is the program point where
651 BB ends. The function updates this counter and returns in
652 CURR_POINT the program point where BB starts. The function also
653 does local live info updates and can delete the dead insns if
654 DEAD_INSN_P. It returns true if pseudo live info was
655 changed at the BB start. */
656 static bool
657 process_bb_lives (basic_block bb, int &curr_point, bool dead_insn_p)
659 int i, regno, freq;
660 unsigned int j;
661 bitmap_iterator bi;
662 bitmap reg_live_out;
663 unsigned int px;
664 rtx_insn *next;
665 rtx link, *link_loc;
666 bool need_curr_point_incr;
668 reg_live_out = df_get_live_out (bb);
669 sparseset_clear (pseudos_live);
670 sparseset_clear (pseudos_live_through_calls);
671 sparseset_clear (pseudos_live_through_setjumps);
672 REG_SET_TO_HARD_REG_SET (hard_regs_live, reg_live_out);
673 AND_COMPL_HARD_REG_SET (hard_regs_live, eliminable_regset);
674 EXECUTE_IF_SET_IN_BITMAP (reg_live_out, FIRST_PSEUDO_REGISTER, j, bi)
675 mark_pseudo_live (j, curr_point);
677 bb_gen_pseudos = &get_bb_data (bb)->gen_pseudos;
678 bb_killed_pseudos = &get_bb_data (bb)->killed_pseudos;
679 bitmap_clear (bb_gen_pseudos);
680 bitmap_clear (bb_killed_pseudos);
681 freq = REG_FREQ_FROM_BB (bb);
683 if (lra_dump_file != NULL)
684 fprintf (lra_dump_file, " BB %d\n", bb->index);
686 /* Scan the code of this basic block, noting which pseudos and hard
687 regs are born or die.
689 Note that this loop treats uninitialized values as live until the
690 beginning of the block. For example, if an instruction uses
691 (reg:DI foo), and only (subreg:SI (reg:DI foo) 0) is ever set,
692 FOO will remain live until the beginning of the block. Likewise
693 if FOO is not set at all. This is unnecessarily pessimistic, but
694 it probably doesn't matter much in practice. */
695 FOR_BB_INSNS_REVERSE_SAFE (bb, curr_insn, next)
697 bool call_p;
698 int dst_regno, src_regno;
699 rtx set;
700 struct lra_insn_reg *reg;
702 if (!NONDEBUG_INSN_P (curr_insn))
703 continue;
705 curr_id = lra_get_insn_recog_data (curr_insn);
706 curr_static_id = curr_id->insn_static_data;
707 if (lra_dump_file != NULL)
708 fprintf (lra_dump_file, " Insn %u: point = %d\n",
709 INSN_UID (curr_insn), curr_point);
711 set = single_set (curr_insn);
713 if (dead_insn_p && set != NULL_RTX
714 && REG_P (SET_DEST (set)) && REGNO (SET_DEST (set)) >= FIRST_PSEUDO_REGISTER
715 && find_reg_note (curr_insn, REG_EH_REGION, NULL_RTX) == NULL_RTX
716 && ! may_trap_p (PATTERN (curr_insn))
717 /* Don't do premature remove of pic offset pseudo as we can
718 start to use it after some reload generation. */
719 && (pic_offset_table_rtx == NULL_RTX
720 || pic_offset_table_rtx != SET_DEST (set)))
722 bool remove_p = true;
724 for (reg = curr_id->regs; reg != NULL; reg = reg->next)
725 if (reg->type != OP_IN && sparseset_bit_p (pseudos_live, reg->regno))
727 remove_p = false;
728 break;
730 for (reg = curr_static_id->hard_regs; reg != NULL; reg = reg->next)
731 if (reg->type != OP_IN)
733 remove_p = false;
734 break;
736 if (remove_p && ! volatile_refs_p (PATTERN (curr_insn)))
738 dst_regno = REGNO (SET_DEST (set));
739 if (lra_dump_file != NULL)
740 fprintf (lra_dump_file, " Deleting dead insn %u\n",
741 INSN_UID (curr_insn));
742 lra_set_insn_deleted (curr_insn);
743 if (lra_reg_info[dst_regno].nrefs == 0)
745 /* There might be some debug insns with the pseudo. */
746 unsigned int uid;
747 rtx_insn *insn;
749 bitmap_copy (&temp_bitmap, &lra_reg_info[dst_regno].insn_bitmap);
750 EXECUTE_IF_SET_IN_BITMAP (&temp_bitmap, 0, uid, bi)
752 insn = lra_insn_recog_data[uid]->insn;
753 lra_substitute_pseudo_within_insn (insn, dst_regno,
754 SET_SRC (set));
755 lra_update_insn_regno_info (insn);
758 continue;
762 /* Update max ref width and hard reg usage. */
763 for (reg = curr_id->regs; reg != NULL; reg = reg->next)
764 if (reg->regno >= FIRST_PSEUDO_REGISTER
765 && (GET_MODE_SIZE (reg->biggest_mode)
766 > GET_MODE_SIZE (lra_reg_info[reg->regno].biggest_mode)))
767 lra_reg_info[reg->regno].biggest_mode = reg->biggest_mode;
768 else if (reg->regno < FIRST_PSEUDO_REGISTER)
769 lra_hard_reg_usage[reg->regno] += freq;
771 call_p = CALL_P (curr_insn);
772 if (complete_info_p
773 && set != NULL_RTX
774 && REG_P (SET_DEST (set)) && REG_P (SET_SRC (set))
775 /* Check that source regno does not conflict with
776 destination regno to exclude most impossible
777 preferences. */
778 && ((((src_regno = REGNO (SET_SRC (set))) >= FIRST_PSEUDO_REGISTER
779 && ! sparseset_bit_p (pseudos_live, src_regno))
780 || (src_regno < FIRST_PSEUDO_REGISTER
781 && ! TEST_HARD_REG_BIT (hard_regs_live, src_regno)))
782 /* It might be 'inheritance pseudo <- reload pseudo'. */
783 || (src_regno >= lra_constraint_new_regno_start
784 && ((int) REGNO (SET_DEST (set))
785 >= lra_constraint_new_regno_start)
786 /* Remember to skip special cases where src/dest regnos are
787 the same, e.g. insn SET pattern has matching constraints
788 like =r,0. */
789 && src_regno != (int) REGNO (SET_DEST (set)))))
791 int hard_regno = -1, regno = -1;
793 dst_regno = REGNO (SET_DEST (set));
794 if (dst_regno >= lra_constraint_new_regno_start
795 && src_regno >= lra_constraint_new_regno_start)
796 lra_create_copy (dst_regno, src_regno, freq);
797 else if (dst_regno >= lra_constraint_new_regno_start)
799 if ((hard_regno = src_regno) >= FIRST_PSEUDO_REGISTER)
800 hard_regno = reg_renumber[src_regno];
801 regno = dst_regno;
803 else if (src_regno >= lra_constraint_new_regno_start)
805 if ((hard_regno = dst_regno) >= FIRST_PSEUDO_REGISTER)
806 hard_regno = reg_renumber[dst_regno];
807 regno = src_regno;
809 if (regno >= 0 && hard_regno >= 0)
810 lra_setup_reload_pseudo_preferenced_hard_reg
811 (regno, hard_regno, freq);
814 sparseset_clear (start_living);
816 /* Try to avoid unnecessary program point increments, this saves
817 a lot of time in remove_some_program_points_and_update_live_ranges.
818 We only need an increment if something becomes live or dies at this
819 program point. */
820 need_curr_point_incr = false;
822 /* Mark each defined value as live. We need to do this for
823 unused values because they still conflict with quantities
824 that are live at the time of the definition. */
825 for (reg = curr_id->regs; reg != NULL; reg = reg->next)
826 if (reg->type != OP_IN)
828 need_curr_point_incr
829 |= mark_regno_live (reg->regno, reg->biggest_mode,
830 curr_point);
831 check_pseudos_live_through_calls (reg->regno);
834 for (reg = curr_static_id->hard_regs; reg != NULL; reg = reg->next)
835 if (reg->type != OP_IN)
836 make_hard_regno_born (reg->regno);
838 sparseset_copy (unused_set, start_living);
840 sparseset_clear (start_dying);
842 /* See which defined values die here. */
843 for (reg = curr_id->regs; reg != NULL; reg = reg->next)
844 if (reg->type == OP_OUT && ! reg->early_clobber && ! reg->subreg_p)
845 need_curr_point_incr
846 |= mark_regno_dead (reg->regno, reg->biggest_mode,
847 curr_point);
849 for (reg = curr_static_id->hard_regs; reg != NULL; reg = reg->next)
850 if (reg->type == OP_OUT && ! reg->early_clobber && ! reg->subreg_p)
851 make_hard_regno_dead (reg->regno);
853 if (call_p)
855 if (flag_ipa_ra)
857 HARD_REG_SET this_call_used_reg_set;
858 get_call_reg_set_usage (curr_insn, &this_call_used_reg_set,
859 call_used_reg_set);
861 EXECUTE_IF_SET_IN_SPARSESET (pseudos_live, j)
862 IOR_HARD_REG_SET (lra_reg_info[j].actual_call_used_reg_set,
863 this_call_used_reg_set);
866 sparseset_ior (pseudos_live_through_calls,
867 pseudos_live_through_calls, pseudos_live);
868 if (cfun->has_nonlocal_label
869 || find_reg_note (curr_insn, REG_SETJMP,
870 NULL_RTX) != NULL_RTX)
871 sparseset_ior (pseudos_live_through_setjumps,
872 pseudos_live_through_setjumps, pseudos_live);
875 /* Increment the current program point if we must. */
876 if (need_curr_point_incr)
877 next_program_point (curr_point, freq);
879 sparseset_clear (start_living);
881 need_curr_point_incr = false;
883 /* Mark each used value as live. */
884 for (reg = curr_id->regs; reg != NULL; reg = reg->next)
885 if (reg->type == OP_IN)
887 need_curr_point_incr
888 |= mark_regno_live (reg->regno, reg->biggest_mode,
889 curr_point);
890 check_pseudos_live_through_calls (reg->regno);
893 for (reg = curr_static_id->hard_regs; reg != NULL; reg = reg->next)
894 if (reg->type == OP_IN)
895 make_hard_regno_born (reg->regno);
897 if (curr_id->arg_hard_regs != NULL)
898 /* Make argument hard registers live. */
899 for (i = 0; (regno = curr_id->arg_hard_regs[i]) >= 0; i++)
900 make_hard_regno_born (regno);
902 sparseset_and_compl (dead_set, start_living, start_dying);
904 /* Mark early clobber outputs dead. */
905 for (reg = curr_id->regs; reg != NULL; reg = reg->next)
906 if (reg->type == OP_OUT && reg->early_clobber && ! reg->subreg_p)
907 need_curr_point_incr
908 |= mark_regno_dead (reg->regno, reg->biggest_mode,
909 curr_point);
911 for (reg = curr_static_id->hard_regs; reg != NULL; reg = reg->next)
912 if (reg->type == OP_OUT && reg->early_clobber && ! reg->subreg_p)
913 make_hard_regno_dead (reg->regno);
915 if (need_curr_point_incr)
916 next_program_point (curr_point, freq);
918 /* Update notes. */
919 for (link_loc = &REG_NOTES (curr_insn); (link = *link_loc) != NULL_RTX;)
921 if (REG_NOTE_KIND (link) != REG_DEAD
922 && REG_NOTE_KIND (link) != REG_UNUSED)
924 else if (REG_P (XEXP (link, 0)))
926 regno = REGNO (XEXP (link, 0));
927 if ((REG_NOTE_KIND (link) == REG_DEAD
928 && ! sparseset_bit_p (dead_set, regno))
929 || (REG_NOTE_KIND (link) == REG_UNUSED
930 && ! sparseset_bit_p (unused_set, regno)))
932 *link_loc = XEXP (link, 1);
933 continue;
935 if (REG_NOTE_KIND (link) == REG_DEAD)
936 sparseset_clear_bit (dead_set, regno);
937 else if (REG_NOTE_KIND (link) == REG_UNUSED)
938 sparseset_clear_bit (unused_set, regno);
940 link_loc = &XEXP (link, 1);
942 EXECUTE_IF_SET_IN_SPARSESET (dead_set, j)
943 add_reg_note (curr_insn, REG_DEAD, regno_reg_rtx[j]);
944 EXECUTE_IF_SET_IN_SPARSESET (unused_set, j)
945 add_reg_note (curr_insn, REG_UNUSED, regno_reg_rtx[j]);
948 #ifdef EH_RETURN_DATA_REGNO
949 if (bb_has_eh_pred (bb))
950 for (j = 0; ; ++j)
952 unsigned int regno = EH_RETURN_DATA_REGNO (j);
954 if (regno == INVALID_REGNUM)
955 break;
956 make_hard_regno_born (regno);
958 #endif
960 /* Pseudos can't go in stack regs at the start of a basic block that
961 is reached by an abnormal edge. Likewise for call clobbered regs,
962 because caller-save, fixup_abnormal_edges and possibly the table
963 driven EH machinery are not quite ready to handle such pseudos
964 live across such edges. */
965 if (bb_has_abnormal_pred (bb))
967 #ifdef STACK_REGS
968 EXECUTE_IF_SET_IN_SPARSESET (pseudos_live, px)
969 lra_reg_info[px].no_stack_p = true;
970 for (px = FIRST_STACK_REG; px <= LAST_STACK_REG; px++)
971 make_hard_regno_born (px);
972 #endif
973 /* No need to record conflicts for call clobbered regs if we
974 have nonlocal labels around, as we don't ever try to
975 allocate such regs in this case. */
976 if (!cfun->has_nonlocal_label && bb_has_abnormal_call_pred (bb))
977 for (px = 0; px < FIRST_PSEUDO_REGISTER; px++)
978 if (call_used_regs[px])
979 make_hard_regno_born (px);
982 bool live_change_p = false;
983 /* Check if bb border live info was changed. */
984 unsigned int live_pseudos_num = 0;
985 EXECUTE_IF_SET_IN_BITMAP (df_get_live_in (bb),
986 FIRST_PSEUDO_REGISTER, j, bi)
988 live_pseudos_num++;
989 if (! sparseset_bit_p (pseudos_live, j))
991 live_change_p = true;
992 if (lra_dump_file != NULL)
993 fprintf (lra_dump_file,
994 " r%d is removed as live at bb%d start\n", j, bb->index);
995 break;
998 if (! live_change_p
999 && sparseset_cardinality (pseudos_live) != live_pseudos_num)
1001 live_change_p = true;
1002 if (lra_dump_file != NULL)
1003 EXECUTE_IF_SET_IN_SPARSESET (pseudos_live, j)
1004 if (! bitmap_bit_p (df_get_live_in (bb), j))
1005 fprintf (lra_dump_file,
1006 " r%d is added to live at bb%d start\n", j, bb->index);
1008 /* See if we'll need an increment at the end of this basic block.
1009 An increment is needed if the PSEUDOS_LIVE set is not empty,
1010 to make sure the finish points are set up correctly. */
1011 need_curr_point_incr = (sparseset_cardinality (pseudos_live) > 0);
1013 EXECUTE_IF_SET_IN_SPARSESET (pseudos_live, i)
1014 mark_pseudo_dead (i, curr_point);
1016 EXECUTE_IF_SET_IN_BITMAP (df_get_live_in (bb), FIRST_PSEUDO_REGISTER, j, bi)
1018 if (sparseset_cardinality (pseudos_live_through_calls) == 0)
1019 break;
1020 if (sparseset_bit_p (pseudos_live_through_calls, j))
1021 check_pseudos_live_through_calls (j);
1024 if (need_curr_point_incr)
1025 next_program_point (curr_point, freq);
1027 return live_change_p;
1030 /* Compress pseudo live ranges by removing program points where
1031 nothing happens. Complexity of many algorithms in LRA is linear
1032 function of program points number. To speed up the code we try to
1033 minimize the number of the program points here. */
1034 static void
1035 remove_some_program_points_and_update_live_ranges (void)
1037 unsigned i;
1038 int n, max_regno;
1039 int *map;
1040 lra_live_range_t r, prev_r, next_r;
1041 sbitmap born_or_dead, born, dead;
1042 sbitmap_iterator sbi;
1043 bool born_p, dead_p, prev_born_p, prev_dead_p;
1045 born = sbitmap_alloc (lra_live_max_point);
1046 dead = sbitmap_alloc (lra_live_max_point);
1047 bitmap_clear (born);
1048 bitmap_clear (dead);
1049 max_regno = max_reg_num ();
1050 for (i = FIRST_PSEUDO_REGISTER; i < (unsigned) max_regno; i++)
1052 for (r = lra_reg_info[i].live_ranges; r != NULL; r = r->next)
1054 lra_assert (r->start <= r->finish);
1055 bitmap_set_bit (born, r->start);
1056 bitmap_set_bit (dead, r->finish);
1059 born_or_dead = sbitmap_alloc (lra_live_max_point);
1060 bitmap_ior (born_or_dead, born, dead);
1061 map = XCNEWVEC (int, lra_live_max_point);
1062 n = -1;
1063 prev_born_p = prev_dead_p = false;
1064 EXECUTE_IF_SET_IN_BITMAP (born_or_dead, 0, i, sbi)
1066 born_p = bitmap_bit_p (born, i);
1067 dead_p = bitmap_bit_p (dead, i);
1068 if ((prev_born_p && ! prev_dead_p && born_p && ! dead_p)
1069 || (prev_dead_p && ! prev_born_p && dead_p && ! born_p))
1071 map[i] = n;
1072 lra_point_freq[n] = MAX (lra_point_freq[n], lra_point_freq[i]);
1074 else
1076 map[i] = ++n;
1077 lra_point_freq[n] = lra_point_freq[i];
1079 prev_born_p = born_p;
1080 prev_dead_p = dead_p;
1082 sbitmap_free (born_or_dead);
1083 sbitmap_free (born);
1084 sbitmap_free (dead);
1085 n++;
1086 if (lra_dump_file != NULL)
1087 fprintf (lra_dump_file, "Compressing live ranges: from %d to %d - %d%%\n",
1088 lra_live_max_point, n, 100 * n / lra_live_max_point);
1089 if (n < lra_live_max_point)
1091 lra_live_max_point = n;
1092 for (i = FIRST_PSEUDO_REGISTER; i < (unsigned) max_regno; i++)
1094 for (prev_r = NULL, r = lra_reg_info[i].live_ranges;
1095 r != NULL;
1096 r = next_r)
1098 next_r = r->next;
1099 r->start = map[r->start];
1100 r->finish = map[r->finish];
1101 if (prev_r == NULL || prev_r->start > r->finish + 1)
1103 prev_r = r;
1104 continue;
1106 prev_r->start = r->start;
1107 prev_r->next = next_r;
1108 free_live_range (r);
1112 free (map);
1115 /* Print live ranges R to file F. */
1116 void
1117 lra_print_live_range_list (FILE *f, lra_live_range_t r)
1119 for (; r != NULL; r = r->next)
1120 fprintf (f, " [%d..%d]", r->start, r->finish);
1121 fprintf (f, "\n");
1124 DEBUG_FUNCTION void
1125 debug (lra_live_range &ref)
1127 lra_print_live_range_list (stderr, &ref);
1130 DEBUG_FUNCTION void
1131 debug (lra_live_range *ptr)
1133 if (ptr)
1134 debug (*ptr);
1135 else
1136 fprintf (stderr, "<nil>\n");
1139 /* Print live ranges R to stderr. */
1140 void
1141 lra_debug_live_range_list (lra_live_range_t r)
1143 lra_print_live_range_list (stderr, r);
1146 /* Print live ranges of pseudo REGNO to file F. */
1147 static void
1148 print_pseudo_live_ranges (FILE *f, int regno)
1150 if (lra_reg_info[regno].live_ranges == NULL)
1151 return;
1152 fprintf (f, " r%d:", regno);
1153 lra_print_live_range_list (f, lra_reg_info[regno].live_ranges);
1156 /* Print live ranges of pseudo REGNO to stderr. */
1157 void
1158 lra_debug_pseudo_live_ranges (int regno)
1160 print_pseudo_live_ranges (stderr, regno);
1163 /* Print live ranges of all pseudos to file F. */
1164 static void
1165 print_live_ranges (FILE *f)
1167 int i, max_regno;
1169 max_regno = max_reg_num ();
1170 for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
1171 print_pseudo_live_ranges (f, i);
1174 /* Print live ranges of all pseudos to stderr. */
1175 void
1176 lra_debug_live_ranges (void)
1178 print_live_ranges (stderr);
1181 /* Compress pseudo live ranges. */
1182 static void
1183 compress_live_ranges (void)
1185 remove_some_program_points_and_update_live_ranges ();
1186 if (lra_dump_file != NULL)
1188 fprintf (lra_dump_file, "Ranges after the compression:\n");
1189 print_live_ranges (lra_dump_file);
1195 /* The number of the current live range pass. */
1196 int lra_live_range_iter;
1198 /* The function creates live ranges only for memory pseudos (or for
1199 all ones if ALL_P), set up CONFLICT_HARD_REGS for the pseudos. It
1200 also does dead insn elimination if DEAD_INSN_P and global live
1201 analysis only for pseudos and only if the pseudo live info was
1202 changed on a BB border. Return TRUE if the live info was
1203 changed. */
1204 static bool
1205 lra_create_live_ranges_1 (bool all_p, bool dead_insn_p)
1207 basic_block bb;
1208 int i, hard_regno, max_regno = max_reg_num ();
1209 int curr_point;
1210 bool bb_live_change_p, have_referenced_pseudos = false;
1212 timevar_push (TV_LRA_CREATE_LIVE_RANGES);
1214 complete_info_p = all_p;
1215 if (lra_dump_file != NULL)
1216 fprintf (lra_dump_file,
1217 "\n********** Pseudo live ranges #%d: **********\n\n",
1218 ++lra_live_range_iter);
1219 memset (lra_hard_reg_usage, 0, sizeof (lra_hard_reg_usage));
1220 for (i = 0; i < max_regno; i++)
1222 lra_reg_info[i].live_ranges = NULL;
1223 CLEAR_HARD_REG_SET (lra_reg_info[i].conflict_hard_regs);
1224 lra_reg_info[i].preferred_hard_regno1 = -1;
1225 lra_reg_info[i].preferred_hard_regno2 = -1;
1226 lra_reg_info[i].preferred_hard_regno_profit1 = 0;
1227 lra_reg_info[i].preferred_hard_regno_profit2 = 0;
1228 #ifdef STACK_REGS
1229 lra_reg_info[i].no_stack_p = false;
1230 #endif
1231 /* The biggest mode is already set but its value might be to
1232 conservative because of recent transformation. Here in this
1233 file we recalculate it again as it costs practically
1234 nothing. */
1235 if (regno_reg_rtx[i] != NULL_RTX)
1236 lra_reg_info[i].biggest_mode = GET_MODE (regno_reg_rtx[i]);
1237 else
1238 lra_reg_info[i].biggest_mode = VOIDmode;
1239 #ifdef ENABLE_CHECKING
1240 lra_reg_info[i].call_p = false;
1241 #endif
1242 if (i >= FIRST_PSEUDO_REGISTER
1243 && lra_reg_info[i].nrefs != 0)
1245 if ((hard_regno = reg_renumber[i]) >= 0)
1246 lra_hard_reg_usage[hard_regno] += lra_reg_info[i].freq;
1247 have_referenced_pseudos = true;
1250 lra_free_copies ();
1252 /* Under some circumstances, we can have functions without pseudo
1253 registers. For such functions, lra_live_max_point will be 0,
1254 see e.g. PR55604, and there's nothing more to do for us here. */
1255 if (! have_referenced_pseudos)
1257 timevar_pop (TV_LRA_CREATE_LIVE_RANGES);
1258 return false;
1261 pseudos_live = sparseset_alloc (max_regno);
1262 pseudos_live_through_calls = sparseset_alloc (max_regno);
1263 pseudos_live_through_setjumps = sparseset_alloc (max_regno);
1264 start_living = sparseset_alloc (max_regno);
1265 start_dying = sparseset_alloc (max_regno);
1266 dead_set = sparseset_alloc (max_regno);
1267 unused_set = sparseset_alloc (max_regno);
1268 curr_point = 0;
1269 point_freq_vec.create (get_max_uid () * 2);
1270 lra_point_freq = point_freq_vec.address ();
1271 int *post_order_rev_cfg = XNEWVEC (int, last_basic_block_for_fn (cfun));
1272 int n_blocks_inverted = inverted_post_order_compute (post_order_rev_cfg);
1273 lra_assert (n_blocks_inverted == n_basic_blocks_for_fn (cfun));
1274 bb_live_change_p = false;
1275 for (i = n_blocks_inverted - 1; i >= 0; --i)
1277 bb = BASIC_BLOCK_FOR_FN (cfun, post_order_rev_cfg[i]);
1278 if (bb == EXIT_BLOCK_PTR_FOR_FN (cfun) || bb
1279 == ENTRY_BLOCK_PTR_FOR_FN (cfun))
1280 continue;
1281 if (process_bb_lives (bb, curr_point, dead_insn_p))
1282 bb_live_change_p = true;
1284 if (bb_live_change_p)
1286 /* We need to clear pseudo live info as some pseudos can
1287 disappear, e.g. pseudos with used equivalences. */
1288 FOR_EACH_BB_FN (bb, cfun)
1290 bitmap_clear_range (df_get_live_in (bb), FIRST_PSEUDO_REGISTER,
1291 max_regno - FIRST_PSEUDO_REGISTER);
1292 bitmap_clear_range (df_get_live_out (bb), FIRST_PSEUDO_REGISTER,
1293 max_regno - FIRST_PSEUDO_REGISTER);
1295 /* As we did not change CFG since LRA start we can use
1296 DF-infrastructure solver to solve live data flow problem. */
1297 df_simple_dataflow
1298 (DF_BACKWARD, NULL, live_con_fun_0, live_con_fun_n,
1299 live_trans_fun, &all_blocks,
1300 df_get_postorder (DF_BACKWARD), df_get_n_blocks (DF_BACKWARD));
1301 if (lra_dump_file != NULL)
1303 fprintf (lra_dump_file,
1304 "Global pseudo live data have been updated:\n");
1305 basic_block bb;
1306 FOR_EACH_BB_FN (bb, cfun)
1308 bb_data_t bb_info = get_bb_data (bb);
1309 bitmap bb_livein = df_get_live_in (bb);
1310 bitmap bb_liveout = df_get_live_out (bb);
1312 fprintf (lra_dump_file, "\nBB %d:\n", bb->index);
1313 lra_dump_bitmap_with_title (" gen:",
1314 &bb_info->gen_pseudos, bb->index);
1315 lra_dump_bitmap_with_title (" killed:",
1316 &bb_info->killed_pseudos, bb->index);
1317 lra_dump_bitmap_with_title (" livein:", bb_livein, bb->index);
1318 lra_dump_bitmap_with_title (" liveout:", bb_liveout, bb->index);
1322 free (post_order_rev_cfg);
1323 lra_live_max_point = curr_point;
1324 if (lra_dump_file != NULL)
1325 print_live_ranges (lra_dump_file);
1326 /* Clean up. */
1327 sparseset_free (unused_set);
1328 sparseset_free (dead_set);
1329 sparseset_free (start_dying);
1330 sparseset_free (start_living);
1331 sparseset_free (pseudos_live_through_calls);
1332 sparseset_free (pseudos_live_through_setjumps);
1333 sparseset_free (pseudos_live);
1334 compress_live_ranges ();
1335 timevar_pop (TV_LRA_CREATE_LIVE_RANGES);
1336 return bb_live_change_p;
1339 /* The main entry function creates live-ranges and other live info
1340 necessary for the assignment sub-pass. It uses
1341 lra_creates_live_ranges_1 -- so read comments for the
1342 function. */
1343 void
1344 lra_create_live_ranges (bool all_p, bool dead_insn_p)
1346 if (! lra_create_live_ranges_1 (all_p, dead_insn_p))
1347 return;
1348 if (lra_dump_file != NULL)
1349 fprintf (lra_dump_file, "Live info was changed -- recalculate it\n");
1350 /* Live info was changed on a bb border. It means that some info,
1351 e.g. about conflict regs, calls crossed, and live ranges may be
1352 wrong. We need this info for allocation. So recalculate it
1353 again but without removing dead insns which can change live info
1354 again. Repetitive live range calculations are expensive therefore
1355 we stop here as we already have correct info although some
1356 improvement in rare cases could be possible on this sub-pass if
1357 we do dead insn elimination again (still the improvement may
1358 happen later). */
1359 lra_clear_live_ranges ();
1360 bool res = lra_create_live_ranges_1 (all_p, false);
1361 lra_assert (! res);
1364 /* Finish all live ranges. */
1365 void
1366 lra_clear_live_ranges (void)
1368 int i;
1370 for (i = 0; i < max_reg_num (); i++)
1371 free_live_range_list (lra_reg_info[i].live_ranges);
1372 point_freq_vec.release ();
1375 /* Initialize live ranges data once per function. */
1376 void
1377 lra_live_ranges_init (void)
1379 live_range_pool = create_alloc_pool ("live ranges",
1380 sizeof (struct lra_live_range), 100);
1381 bitmap_initialize (&temp_bitmap, &reg_obstack);
1382 initiate_live_solver ();
1385 /* Finish live ranges data once per function. */
1386 void
1387 lra_live_ranges_finish (void)
1389 finish_live_solver ();
1390 bitmap_clear (&temp_bitmap);
1391 free_alloc_pool (live_range_pool);