Fix for ICE with -g on testcase with incomplete types.
[official-gcc.git] / gcc / lra-lives.c
bloba2c55426e934f438e48668d9339aaf1047f88c4a
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 ("live ranges");
112 /* Free live range list LR. */
113 static void
114 free_live_range_list (lra_live_range_t lr)
116 lra_live_range_t next;
118 while (lr != NULL)
120 next = lr->next;
121 delete lr;
122 lr = next;
126 /* Create and return pseudo live range with given attributes. */
127 static lra_live_range_t
128 create_live_range (int regno, int start, int finish, lra_live_range_t next)
130 lra_live_range_t p = new lra_live_range;
131 p->regno = regno;
132 p->start = start;
133 p->finish = finish;
134 p->next = next;
135 return p;
138 /* Copy live range R and return the result. */
139 static lra_live_range_t
140 copy_live_range (lra_live_range_t r)
142 return new lra_live_range (*r);
145 /* Copy live range list given by its head R and return the result. */
146 lra_live_range_t
147 lra_copy_live_range_list (lra_live_range_t r)
149 lra_live_range_t p, first, *chain;
151 first = NULL;
152 for (chain = &first; r != NULL; r = r->next)
154 p = copy_live_range (r);
155 *chain = p;
156 chain = &p->next;
158 return first;
161 /* Merge *non-intersected* ranges R1 and R2 and returns the result.
162 The function maintains the order of ranges and tries to minimize
163 size of the result range list. Ranges R1 and R2 may not be used
164 after the call. */
165 lra_live_range_t
166 lra_merge_live_ranges (lra_live_range_t r1, lra_live_range_t r2)
168 lra_live_range_t first, last;
170 if (r1 == NULL)
171 return r2;
172 if (r2 == NULL)
173 return r1;
174 for (first = last = NULL; r1 != NULL && r2 != NULL;)
176 if (r1->start < r2->start)
177 std::swap (r1, r2);
179 if (r1->start == r2->finish + 1)
181 /* Joint ranges: merge r1 and r2 into r1. */
182 r1->start = r2->start;
183 lra_live_range_t temp = r2;
184 r2 = r2->next;
185 delete temp;
187 else
189 gcc_assert (r2->finish + 1 < r1->start);
190 /* Add r1 to the result. */
191 if (first == NULL)
192 first = last = r1;
193 else
195 last->next = r1;
196 last = r1;
198 r1 = r1->next;
201 if (r1 != NULL)
203 if (first == NULL)
204 first = r1;
205 else
206 last->next = r1;
208 else
210 lra_assert (r2 != NULL);
211 if (first == NULL)
212 first = r2;
213 else
214 last->next = r2;
216 return first;
219 /* Return TRUE if live ranges R1 and R2 intersect. */
220 bool
221 lra_intersected_live_ranges_p (lra_live_range_t r1, lra_live_range_t r2)
223 /* Remember the live ranges are always kept ordered. */
224 while (r1 != NULL && r2 != NULL)
226 if (r1->start > r2->finish)
227 r1 = r1->next;
228 else if (r2->start > r1->finish)
229 r2 = r2->next;
230 else
231 return true;
233 return false;
236 /* The function processing birth of hard register REGNO. It updates
237 living hard regs, START_LIVING, and conflict hard regs for living
238 pseudos. Conflict hard regs for the pic pseudo is not updated if
239 REGNO is REAL_PIC_OFFSET_TABLE_REGNUM and CHECK_PIC_PSEUDO_P is
240 true. */
241 static void
242 make_hard_regno_born (int regno, bool check_pic_pseudo_p ATTRIBUTE_UNUSED)
244 unsigned int i;
246 lra_assert (regno < FIRST_PSEUDO_REGISTER);
247 if (TEST_HARD_REG_BIT (hard_regs_live, regno))
248 return;
249 SET_HARD_REG_BIT (hard_regs_live, regno);
250 sparseset_set_bit (start_living, regno);
251 EXECUTE_IF_SET_IN_SPARSESET (pseudos_live, i)
252 #ifdef REAL_PIC_OFFSET_TABLE_REGNUM
253 if (! check_pic_pseudo_p
254 || regno != REAL_PIC_OFFSET_TABLE_REGNUM
255 || pic_offset_table_rtx == NULL
256 || i != REGNO (pic_offset_table_rtx))
257 #endif
258 SET_HARD_REG_BIT (lra_reg_info[i].conflict_hard_regs, regno);
261 /* Process the death of hard register REGNO. This updates
262 hard_regs_live and START_DYING. */
263 static void
264 make_hard_regno_dead (int regno)
266 lra_assert (regno < FIRST_PSEUDO_REGISTER);
267 if (! TEST_HARD_REG_BIT (hard_regs_live, regno))
268 return;
269 sparseset_set_bit (start_dying, regno);
270 CLEAR_HARD_REG_BIT (hard_regs_live, regno);
273 /* Mark pseudo REGNO as living at program point POINT, update conflicting
274 hard registers of the pseudo and START_LIVING, and start a new live
275 range for the pseudo corresponding to REGNO if it is necessary. */
276 static void
277 mark_pseudo_live (int regno, int point)
279 lra_live_range_t p;
281 lra_assert (regno >= FIRST_PSEUDO_REGISTER);
282 lra_assert (! sparseset_bit_p (pseudos_live, regno));
283 sparseset_set_bit (pseudos_live, regno);
284 IOR_HARD_REG_SET (lra_reg_info[regno].conflict_hard_regs, hard_regs_live);
286 if ((complete_info_p || lra_get_regno_hard_regno (regno) < 0)
287 && ((p = lra_reg_info[regno].live_ranges) == NULL
288 || (p->finish != point && p->finish + 1 != point)))
289 lra_reg_info[regno].live_ranges
290 = create_live_range (regno, point, -1, p);
291 sparseset_set_bit (start_living, regno);
294 /* Mark pseudo REGNO as not living at program point POINT and update
295 START_DYING.
296 This finishes the current live range for the pseudo corresponding
297 to REGNO. */
298 static void
299 mark_pseudo_dead (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_clear_bit (pseudos_live, regno);
306 sparseset_set_bit (start_dying, regno);
307 if (complete_info_p || lra_get_regno_hard_regno (regno) < 0)
309 p = lra_reg_info[regno].live_ranges;
310 lra_assert (p != NULL);
311 p->finish = point;
315 /* The corresponding bitmaps of BB currently being processed. */
316 static bitmap bb_killed_pseudos, bb_gen_pseudos;
318 /* Mark register REGNO (pseudo or hard register) in MODE as live at
319 program point POINT. Update BB_GEN_PSEUDOS.
320 Return TRUE if the liveness tracking sets were modified, or FALSE
321 if nothing changed. */
322 static bool
323 mark_regno_live (int regno, machine_mode mode, int point)
325 int last;
326 bool changed = false;
328 if (regno < FIRST_PSEUDO_REGISTER)
330 for (last = regno + hard_regno_nregs[regno][mode];
331 regno < last;
332 regno++)
333 make_hard_regno_born (regno, false);
335 else
337 if (! sparseset_bit_p (pseudos_live, regno))
339 mark_pseudo_live (regno, point);
340 changed = true;
342 bitmap_set_bit (bb_gen_pseudos, regno);
344 return changed;
348 /* Mark register REGNO in MODE as dead at program point POINT. Update
349 BB_GEN_PSEUDOS and BB_KILLED_PSEUDOS. Return TRUE if the liveness
350 tracking sets were modified, or FALSE if nothing changed. */
351 static bool
352 mark_regno_dead (int regno, machine_mode mode, int point)
354 int last;
355 bool changed = false;
357 if (regno < FIRST_PSEUDO_REGISTER)
359 for (last = regno + hard_regno_nregs[regno][mode];
360 regno < last;
361 regno++)
362 make_hard_regno_dead (regno);
364 else
366 if (sparseset_bit_p (pseudos_live, regno))
368 mark_pseudo_dead (regno, point);
369 changed = true;
371 bitmap_clear_bit (bb_gen_pseudos, regno);
372 bitmap_set_bit (bb_killed_pseudos, regno);
374 return changed;
379 /* This page contains code for making global live analysis of pseudos.
380 The code works only when pseudo live info is changed on a BB
381 border. That might be a consequence of some global transformations
382 in LRA, e.g. PIC pseudo reuse or rematerialization. */
384 /* Structure describing local BB data used for pseudo
385 live-analysis. */
386 struct bb_data_pseudos
388 /* Basic block about which the below data are. */
389 basic_block bb;
390 bitmap_head killed_pseudos; /* pseudos killed in the BB. */
391 bitmap_head gen_pseudos; /* pseudos generated in the BB. */
394 /* Array for all BB data. Indexed by the corresponding BB index. */
395 typedef struct bb_data_pseudos *bb_data_t;
397 /* All basic block data are referred through the following array. */
398 static bb_data_t bb_data;
400 /* Two small functions for access to the bb data. */
401 static inline bb_data_t
402 get_bb_data (basic_block bb)
404 return &bb_data[(bb)->index];
407 static inline bb_data_t
408 get_bb_data_by_index (int index)
410 return &bb_data[index];
413 /* Bitmap with all hard regs. */
414 static bitmap_head all_hard_regs_bitmap;
416 /* The transfer function used by the DF equation solver to propagate
417 live info through block with BB_INDEX according to the following
418 equation:
420 bb.livein = (bb.liveout - bb.kill) OR bb.gen
422 static bool
423 live_trans_fun (int bb_index)
425 basic_block bb = get_bb_data_by_index (bb_index)->bb;
426 bitmap bb_liveout = df_get_live_out (bb);
427 bitmap bb_livein = df_get_live_in (bb);
428 bb_data_t bb_info = get_bb_data (bb);
430 bitmap_and_compl (&temp_bitmap, bb_liveout, &all_hard_regs_bitmap);
431 return bitmap_ior_and_compl (bb_livein, &bb_info->gen_pseudos,
432 &temp_bitmap, &bb_info->killed_pseudos);
435 /* The confluence function used by the DF equation solver to set up
436 live info for a block BB without predecessor. */
437 static void
438 live_con_fun_0 (basic_block bb)
440 bitmap_and_into (df_get_live_out (bb), &all_hard_regs_bitmap);
443 /* The confluence function used by the DF equation solver to propagate
444 live info from successor to predecessor on edge E according to the
445 following equation:
447 bb.liveout = 0 for entry block | OR (livein of successors)
449 static bool
450 live_con_fun_n (edge e)
452 basic_block bb = e->src;
453 basic_block dest = e->dest;
454 bitmap bb_liveout = df_get_live_out (bb);
455 bitmap dest_livein = df_get_live_in (dest);
457 return bitmap_ior_and_compl_into (bb_liveout,
458 dest_livein, &all_hard_regs_bitmap);
461 /* Indexes of all function blocks. */
462 static bitmap_head all_blocks;
464 /* Allocate and initialize data needed for global pseudo live
465 analysis. */
466 static void
467 initiate_live_solver (void)
469 bitmap_initialize (&all_hard_regs_bitmap, &reg_obstack);
470 bitmap_set_range (&all_hard_regs_bitmap, 0, FIRST_PSEUDO_REGISTER);
471 bb_data = XNEWVEC (struct bb_data_pseudos, last_basic_block_for_fn (cfun));
472 bitmap_initialize (&all_blocks, &reg_obstack);
474 basic_block bb;
475 FOR_ALL_BB_FN (bb, cfun)
477 bb_data_t bb_info = get_bb_data (bb);
478 bb_info->bb = bb;
479 bitmap_initialize (&bb_info->killed_pseudos, &reg_obstack);
480 bitmap_initialize (&bb_info->gen_pseudos, &reg_obstack);
481 bitmap_set_bit (&all_blocks, bb->index);
485 /* Free all data needed for global pseudo live analysis. */
486 static void
487 finish_live_solver (void)
489 basic_block bb;
491 bitmap_clear (&all_blocks);
492 FOR_ALL_BB_FN (bb, cfun)
494 bb_data_t bb_info = get_bb_data (bb);
495 bitmap_clear (&bb_info->killed_pseudos);
496 bitmap_clear (&bb_info->gen_pseudos);
498 free (bb_data);
499 bitmap_clear (&all_hard_regs_bitmap);
504 /* Insn currently scanned. */
505 static rtx_insn *curr_insn;
506 /* The insn data. */
507 static lra_insn_recog_data_t curr_id;
508 /* The insn static data. */
509 static struct lra_static_insn_data *curr_static_id;
511 /* Vec containing execution frequencies of program points. */
512 static vec<int> point_freq_vec;
514 /* The start of the above vector elements. */
515 int *lra_point_freq;
517 /* Increment the current program point POINT to the next point which has
518 execution frequency FREQ. */
519 static void
520 next_program_point (int &point, int freq)
522 point_freq_vec.safe_push (freq);
523 lra_point_freq = point_freq_vec.address ();
524 point++;
527 /* Update the preference of HARD_REGNO for pseudo REGNO by PROFIT. */
528 void
529 lra_setup_reload_pseudo_preferenced_hard_reg (int regno,
530 int hard_regno, int profit)
532 lra_assert (regno >= lra_constraint_new_regno_start);
533 if (lra_reg_info[regno].preferred_hard_regno1 == hard_regno)
534 lra_reg_info[regno].preferred_hard_regno_profit1 += profit;
535 else if (lra_reg_info[regno].preferred_hard_regno2 == hard_regno)
536 lra_reg_info[regno].preferred_hard_regno_profit2 += profit;
537 else if (lra_reg_info[regno].preferred_hard_regno1 < 0)
539 lra_reg_info[regno].preferred_hard_regno1 = hard_regno;
540 lra_reg_info[regno].preferred_hard_regno_profit1 = profit;
542 else if (lra_reg_info[regno].preferred_hard_regno2 < 0
543 || profit > lra_reg_info[regno].preferred_hard_regno_profit2)
545 lra_reg_info[regno].preferred_hard_regno2 = hard_regno;
546 lra_reg_info[regno].preferred_hard_regno_profit2 = profit;
548 else
549 return;
550 /* Keep the 1st hard regno as more profitable. */
551 if (lra_reg_info[regno].preferred_hard_regno1 >= 0
552 && lra_reg_info[regno].preferred_hard_regno2 >= 0
553 && (lra_reg_info[regno].preferred_hard_regno_profit2
554 > lra_reg_info[regno].preferred_hard_regno_profit1))
556 std::swap (lra_reg_info[regno].preferred_hard_regno1,
557 lra_reg_info[regno].preferred_hard_regno2);
558 std::swap (lra_reg_info[regno].preferred_hard_regno_profit1,
559 lra_reg_info[regno].preferred_hard_regno_profit2);
561 if (lra_dump_file != NULL)
563 if ((hard_regno = lra_reg_info[regno].preferred_hard_regno1) >= 0)
564 fprintf (lra_dump_file,
565 " Hard reg %d is preferable by r%d with profit %d\n",
566 hard_regno, regno,
567 lra_reg_info[regno].preferred_hard_regno_profit1);
568 if ((hard_regno = lra_reg_info[regno].preferred_hard_regno2) >= 0)
569 fprintf (lra_dump_file,
570 " Hard reg %d is preferable by r%d with profit %d\n",
571 hard_regno, regno,
572 lra_reg_info[regno].preferred_hard_regno_profit2);
576 /* Check that REGNO living through calls and setjumps, set up conflict
577 regs, and clear corresponding bits in PSEUDOS_LIVE_THROUGH_CALLS and
578 PSEUDOS_LIVE_THROUGH_SETJUMPS. */
579 static inline void
580 check_pseudos_live_through_calls (int regno)
582 int hr;
584 if (! sparseset_bit_p (pseudos_live_through_calls, regno))
585 return;
586 sparseset_clear_bit (pseudos_live_through_calls, regno);
587 IOR_HARD_REG_SET (lra_reg_info[regno].conflict_hard_regs,
588 call_used_reg_set);
590 for (hr = 0; hr < FIRST_PSEUDO_REGISTER; hr++)
591 if (HARD_REGNO_CALL_PART_CLOBBERED (hr, PSEUDO_REGNO_MODE (regno)))
592 SET_HARD_REG_BIT (lra_reg_info[regno].conflict_hard_regs, hr);
593 lra_reg_info[regno].call_p = true;
594 if (! sparseset_bit_p (pseudos_live_through_setjumps, regno))
595 return;
596 sparseset_clear_bit (pseudos_live_through_setjumps, regno);
597 /* Don't allocate pseudos that cross setjmps or any call, if this
598 function receives a nonlocal goto. */
599 SET_HARD_REG_SET (lra_reg_info[regno].conflict_hard_regs);
602 /* Process insns of the basic block BB to update pseudo live ranges,
603 pseudo hard register conflicts, and insn notes. We do it on
604 backward scan of BB insns. CURR_POINT is the program point where
605 BB ends. The function updates this counter and returns in
606 CURR_POINT the program point where BB starts. The function also
607 does local live info updates and can delete the dead insns if
608 DEAD_INSN_P. It returns true if pseudo live info was
609 changed at the BB start. */
610 static bool
611 process_bb_lives (basic_block bb, int &curr_point, bool dead_insn_p)
613 int i, regno, freq;
614 unsigned int j;
615 bitmap_iterator bi;
616 bitmap reg_live_out;
617 unsigned int px;
618 rtx_insn *next;
619 rtx link, *link_loc;
620 bool need_curr_point_incr;
622 reg_live_out = df_get_live_out (bb);
623 sparseset_clear (pseudos_live);
624 sparseset_clear (pseudos_live_through_calls);
625 sparseset_clear (pseudos_live_through_setjumps);
626 REG_SET_TO_HARD_REG_SET (hard_regs_live, reg_live_out);
627 AND_COMPL_HARD_REG_SET (hard_regs_live, eliminable_regset);
628 EXECUTE_IF_SET_IN_BITMAP (reg_live_out, FIRST_PSEUDO_REGISTER, j, bi)
629 mark_pseudo_live (j, curr_point);
631 bb_gen_pseudos = &get_bb_data (bb)->gen_pseudos;
632 bb_killed_pseudos = &get_bb_data (bb)->killed_pseudos;
633 bitmap_clear (bb_gen_pseudos);
634 bitmap_clear (bb_killed_pseudos);
635 freq = REG_FREQ_FROM_BB (bb);
637 if (lra_dump_file != NULL)
638 fprintf (lra_dump_file, " BB %d\n", bb->index);
640 /* Scan the code of this basic block, noting which pseudos and hard
641 regs are born or die.
643 Note that this loop treats uninitialized values as live until the
644 beginning of the block. For example, if an instruction uses
645 (reg:DI foo), and only (subreg:SI (reg:DI foo) 0) is ever set,
646 FOO will remain live until the beginning of the block. Likewise
647 if FOO is not set at all. This is unnecessarily pessimistic, but
648 it probably doesn't matter much in practice. */
649 FOR_BB_INSNS_REVERSE_SAFE (bb, curr_insn, next)
651 bool call_p;
652 int dst_regno, src_regno;
653 rtx set;
654 struct lra_insn_reg *reg;
656 if (!NONDEBUG_INSN_P (curr_insn))
657 continue;
659 curr_id = lra_get_insn_recog_data (curr_insn);
660 curr_static_id = curr_id->insn_static_data;
661 if (lra_dump_file != NULL)
662 fprintf (lra_dump_file, " Insn %u: point = %d\n",
663 INSN_UID (curr_insn), curr_point);
665 set = single_set (curr_insn);
667 if (dead_insn_p && set != NULL_RTX
668 && REG_P (SET_DEST (set)) && REGNO (SET_DEST (set)) >= FIRST_PSEUDO_REGISTER
669 && find_reg_note (curr_insn, REG_EH_REGION, NULL_RTX) == NULL_RTX
670 && ! may_trap_p (PATTERN (curr_insn))
671 /* Don't do premature remove of pic offset pseudo as we can
672 start to use it after some reload generation. */
673 && (pic_offset_table_rtx == NULL_RTX
674 || pic_offset_table_rtx != SET_DEST (set)))
676 bool remove_p = true;
678 for (reg = curr_id->regs; reg != NULL; reg = reg->next)
679 if (reg->type != OP_IN && sparseset_bit_p (pseudos_live, reg->regno))
681 remove_p = false;
682 break;
684 for (reg = curr_static_id->hard_regs; reg != NULL; reg = reg->next)
685 if (reg->type != OP_IN)
687 remove_p = false;
688 break;
690 if (remove_p && ! volatile_refs_p (PATTERN (curr_insn)))
692 dst_regno = REGNO (SET_DEST (set));
693 if (lra_dump_file != NULL)
694 fprintf (lra_dump_file, " Deleting dead insn %u\n",
695 INSN_UID (curr_insn));
696 lra_set_insn_deleted (curr_insn);
697 if (lra_reg_info[dst_regno].nrefs == 0)
699 /* There might be some debug insns with the pseudo. */
700 unsigned int uid;
701 rtx_insn *insn;
703 bitmap_copy (&temp_bitmap, &lra_reg_info[dst_regno].insn_bitmap);
704 EXECUTE_IF_SET_IN_BITMAP (&temp_bitmap, 0, uid, bi)
706 insn = lra_insn_recog_data[uid]->insn;
707 lra_substitute_pseudo_within_insn (insn, dst_regno,
708 SET_SRC (set), true);
709 lra_update_insn_regno_info (insn);
712 continue;
716 /* Update max ref width and hard reg usage. */
717 for (reg = curr_id->regs; reg != NULL; reg = reg->next)
718 if (reg->regno >= FIRST_PSEUDO_REGISTER
719 && (GET_MODE_SIZE (reg->biggest_mode)
720 > GET_MODE_SIZE (lra_reg_info[reg->regno].biggest_mode)))
721 lra_reg_info[reg->regno].biggest_mode = reg->biggest_mode;
722 else if (reg->regno < FIRST_PSEUDO_REGISTER)
723 lra_hard_reg_usage[reg->regno] += freq;
725 call_p = CALL_P (curr_insn);
726 src_regno = (set != NULL_RTX && REG_P (SET_SRC (set))
727 ? REGNO (SET_SRC (set)) : -1);
728 dst_regno = (set != NULL_RTX && REG_P (SET_DEST (set))
729 ? REGNO (SET_DEST (set)) : -1);
730 if (complete_info_p
731 && src_regno >= 0 && dst_regno >= 0
732 /* Check that source regno does not conflict with
733 destination regno to exclude most impossible
734 preferences. */
735 && (((src_regno >= FIRST_PSEUDO_REGISTER
736 && (! sparseset_bit_p (pseudos_live, src_regno)
737 || (dst_regno >= FIRST_PSEUDO_REGISTER
738 && lra_reg_val_equal_p (src_regno,
739 lra_reg_info[dst_regno].val,
740 lra_reg_info[dst_regno].offset))))
741 || (src_regno < FIRST_PSEUDO_REGISTER
742 && ! TEST_HARD_REG_BIT (hard_regs_live, src_regno)))
743 /* It might be 'inheritance pseudo <- reload pseudo'. */
744 || (src_regno >= lra_constraint_new_regno_start
745 && dst_regno >= lra_constraint_new_regno_start
746 /* Remember to skip special cases where src/dest regnos are
747 the same, e.g. insn SET pattern has matching constraints
748 like =r,0. */
749 && src_regno != dst_regno)))
751 int hard_regno = -1, regno = -1;
753 if (dst_regno >= lra_constraint_new_regno_start
754 && src_regno >= lra_constraint_new_regno_start)
756 /* It might be still an original (non-reload) insn with
757 one unused output and a constraint requiring to use
758 the same reg for input/output operands. In this case
759 dst_regno and src_regno have the same value, we don't
760 need a misleading copy for this case. */
761 if (dst_regno != src_regno)
762 lra_create_copy (dst_regno, src_regno, freq);
764 else if (dst_regno >= lra_constraint_new_regno_start)
766 if ((hard_regno = src_regno) >= FIRST_PSEUDO_REGISTER)
767 hard_regno = reg_renumber[src_regno];
768 regno = dst_regno;
770 else if (src_regno >= lra_constraint_new_regno_start)
772 if ((hard_regno = dst_regno) >= FIRST_PSEUDO_REGISTER)
773 hard_regno = reg_renumber[dst_regno];
774 regno = src_regno;
776 if (regno >= 0 && hard_regno >= 0)
777 lra_setup_reload_pseudo_preferenced_hard_reg
778 (regno, hard_regno, freq);
781 sparseset_clear (start_living);
783 /* Try to avoid unnecessary program point increments, this saves
784 a lot of time in remove_some_program_points_and_update_live_ranges.
785 We only need an increment if something becomes live or dies at this
786 program point. */
787 need_curr_point_incr = false;
789 /* Mark each defined value as live. We need to do this for
790 unused values because they still conflict with quantities
791 that are live at the time of the definition. */
792 for (reg = curr_id->regs; reg != NULL; reg = reg->next)
793 if (reg->type != OP_IN)
795 need_curr_point_incr
796 |= mark_regno_live (reg->regno, reg->biggest_mode,
797 curr_point);
798 check_pseudos_live_through_calls (reg->regno);
801 for (reg = curr_static_id->hard_regs; reg != NULL; reg = reg->next)
802 if (reg->type != OP_IN)
803 make_hard_regno_born (reg->regno, false);
805 if (curr_id->arg_hard_regs != NULL)
806 for (i = 0; (regno = curr_id->arg_hard_regs[i]) >= 0; i++)
807 if (regno >= FIRST_PSEUDO_REGISTER)
808 /* It is a clobber. */
809 make_hard_regno_born (regno - FIRST_PSEUDO_REGISTER, false);
811 sparseset_copy (unused_set, start_living);
813 sparseset_clear (start_dying);
815 /* See which defined values die here. */
816 for (reg = curr_id->regs; reg != NULL; reg = reg->next)
817 if (reg->type == OP_OUT && ! reg->early_clobber && ! reg->subreg_p)
818 need_curr_point_incr
819 |= mark_regno_dead (reg->regno, reg->biggest_mode,
820 curr_point);
822 for (reg = curr_static_id->hard_regs; reg != NULL; reg = reg->next)
823 if (reg->type == OP_OUT && ! reg->early_clobber && ! reg->subreg_p)
824 make_hard_regno_dead (reg->regno);
826 if (curr_id->arg_hard_regs != NULL)
827 for (i = 0; (regno = curr_id->arg_hard_regs[i]) >= 0; i++)
828 if (regno >= FIRST_PSEUDO_REGISTER)
829 /* It is a clobber. */
830 make_hard_regno_dead (regno - FIRST_PSEUDO_REGISTER);
832 if (call_p)
834 if (flag_ipa_ra)
836 HARD_REG_SET this_call_used_reg_set;
837 get_call_reg_set_usage (curr_insn, &this_call_used_reg_set,
838 call_used_reg_set);
840 EXECUTE_IF_SET_IN_SPARSESET (pseudos_live, j)
841 IOR_HARD_REG_SET (lra_reg_info[j].actual_call_used_reg_set,
842 this_call_used_reg_set);
845 sparseset_ior (pseudos_live_through_calls,
846 pseudos_live_through_calls, pseudos_live);
847 if (cfun->has_nonlocal_label
848 || find_reg_note (curr_insn, REG_SETJMP,
849 NULL_RTX) != NULL_RTX)
850 sparseset_ior (pseudos_live_through_setjumps,
851 pseudos_live_through_setjumps, pseudos_live);
854 /* Increment the current program point if we must. */
855 if (need_curr_point_incr)
856 next_program_point (curr_point, freq);
858 sparseset_clear (start_living);
860 need_curr_point_incr = false;
862 /* Mark each used value as live. */
863 for (reg = curr_id->regs; reg != NULL; reg = reg->next)
864 if (reg->type == OP_IN)
866 need_curr_point_incr
867 |= mark_regno_live (reg->regno, reg->biggest_mode,
868 curr_point);
869 check_pseudos_live_through_calls (reg->regno);
872 for (reg = curr_static_id->hard_regs; reg != NULL; reg = reg->next)
873 if (reg->type == OP_IN)
874 make_hard_regno_born (reg->regno, false);
876 if (curr_id->arg_hard_regs != NULL)
877 /* Make argument hard registers live. Don't create conflict
878 of used REAL_PIC_OFFSET_TABLE_REGNUM and the pic pseudo. */
879 for (i = 0; (regno = curr_id->arg_hard_regs[i]) >= 0; i++)
880 if (regno < FIRST_PSEUDO_REGISTER)
881 make_hard_regno_born (regno, true);
883 sparseset_and_compl (dead_set, start_living, start_dying);
885 /* Mark early clobber outputs dead. */
886 for (reg = curr_id->regs; reg != NULL; reg = reg->next)
887 if (reg->type == OP_OUT && reg->early_clobber && ! reg->subreg_p)
888 need_curr_point_incr
889 |= mark_regno_dead (reg->regno, reg->biggest_mode,
890 curr_point);
892 for (reg = curr_static_id->hard_regs; reg != NULL; reg = reg->next)
893 if (reg->type == OP_OUT && reg->early_clobber && ! reg->subreg_p)
894 make_hard_regno_dead (reg->regno);
896 if (need_curr_point_incr)
897 next_program_point (curr_point, freq);
899 /* Update notes. */
900 for (link_loc = &REG_NOTES (curr_insn); (link = *link_loc) != NULL_RTX;)
902 if (REG_NOTE_KIND (link) != REG_DEAD
903 && REG_NOTE_KIND (link) != REG_UNUSED)
905 else if (REG_P (XEXP (link, 0)))
907 regno = REGNO (XEXP (link, 0));
908 if ((REG_NOTE_KIND (link) == REG_DEAD
909 && ! sparseset_bit_p (dead_set, regno))
910 || (REG_NOTE_KIND (link) == REG_UNUSED
911 && ! sparseset_bit_p (unused_set, regno)))
913 *link_loc = XEXP (link, 1);
914 continue;
916 if (REG_NOTE_KIND (link) == REG_DEAD)
917 sparseset_clear_bit (dead_set, regno);
918 else if (REG_NOTE_KIND (link) == REG_UNUSED)
919 sparseset_clear_bit (unused_set, regno);
921 link_loc = &XEXP (link, 1);
923 EXECUTE_IF_SET_IN_SPARSESET (dead_set, j)
924 add_reg_note (curr_insn, REG_DEAD, regno_reg_rtx[j]);
925 EXECUTE_IF_SET_IN_SPARSESET (unused_set, j)
926 add_reg_note (curr_insn, REG_UNUSED, regno_reg_rtx[j]);
929 if (bb_has_eh_pred (bb))
930 for (j = 0; ; ++j)
932 unsigned int regno = EH_RETURN_DATA_REGNO (j);
934 if (regno == INVALID_REGNUM)
935 break;
936 make_hard_regno_born (regno, false);
939 /* Pseudos can't go in stack regs at the start of a basic block that
940 is reached by an abnormal edge. Likewise for call clobbered regs,
941 because caller-save, fixup_abnormal_edges and possibly the table
942 driven EH machinery are not quite ready to handle such pseudos
943 live across such edges. */
944 if (bb_has_abnormal_pred (bb))
946 #ifdef STACK_REGS
947 EXECUTE_IF_SET_IN_SPARSESET (pseudos_live, px)
948 lra_reg_info[px].no_stack_p = true;
949 for (px = FIRST_STACK_REG; px <= LAST_STACK_REG; px++)
950 make_hard_regno_born (px, false);
951 #endif
952 /* No need to record conflicts for call clobbered regs if we
953 have nonlocal labels around, as we don't ever try to
954 allocate such regs in this case. */
955 if (!cfun->has_nonlocal_label
956 && has_abnormal_call_or_eh_pred_edge_p (bb))
957 for (px = 0; px < FIRST_PSEUDO_REGISTER; px++)
958 if (call_used_regs[px]
959 #ifdef REAL_PIC_OFFSET_TABLE_REGNUM
960 /* We should create a conflict of PIC pseudo with PIC
961 hard reg as PIC hard reg can have a wrong value after
962 jump described by the abnormal edge. In this case we
963 can not allocate PIC hard reg to PIC pseudo as PIC
964 pseudo will also have a wrong value. */
965 || (px == REAL_PIC_OFFSET_TABLE_REGNUM
966 && pic_offset_table_rtx != NULL_RTX
967 && REGNO (pic_offset_table_rtx) >= FIRST_PSEUDO_REGISTER)
968 #endif
970 make_hard_regno_born (px, false);
973 bool live_change_p = false;
974 /* Check if bb border live info was changed. */
975 unsigned int live_pseudos_num = 0;
976 EXECUTE_IF_SET_IN_BITMAP (df_get_live_in (bb),
977 FIRST_PSEUDO_REGISTER, j, bi)
979 live_pseudos_num++;
980 if (! sparseset_bit_p (pseudos_live, j))
982 live_change_p = true;
983 if (lra_dump_file != NULL)
984 fprintf (lra_dump_file,
985 " r%d is removed as live at bb%d start\n", j, bb->index);
986 break;
989 if (! live_change_p
990 && sparseset_cardinality (pseudos_live) != live_pseudos_num)
992 live_change_p = true;
993 if (lra_dump_file != NULL)
994 EXECUTE_IF_SET_IN_SPARSESET (pseudos_live, j)
995 if (! bitmap_bit_p (df_get_live_in (bb), j))
996 fprintf (lra_dump_file,
997 " r%d is added to live at bb%d start\n", j, bb->index);
999 /* See if we'll need an increment at the end of this basic block.
1000 An increment is needed if the PSEUDOS_LIVE set is not empty,
1001 to make sure the finish points are set up correctly. */
1002 need_curr_point_incr = (sparseset_cardinality (pseudos_live) > 0);
1004 EXECUTE_IF_SET_IN_SPARSESET (pseudos_live, i)
1005 mark_pseudo_dead (i, curr_point);
1007 EXECUTE_IF_SET_IN_BITMAP (df_get_live_in (bb), FIRST_PSEUDO_REGISTER, j, bi)
1009 if (sparseset_cardinality (pseudos_live_through_calls) == 0)
1010 break;
1011 if (sparseset_bit_p (pseudos_live_through_calls, j))
1012 check_pseudos_live_through_calls (j);
1015 if (need_curr_point_incr)
1016 next_program_point (curr_point, freq);
1018 return live_change_p;
1021 /* Compress pseudo live ranges by removing program points where
1022 nothing happens. Complexity of many algorithms in LRA is linear
1023 function of program points number. To speed up the code we try to
1024 minimize the number of the program points here. */
1025 static void
1026 remove_some_program_points_and_update_live_ranges (void)
1028 unsigned i;
1029 int n, max_regno;
1030 int *map;
1031 lra_live_range_t r, prev_r, next_r;
1032 sbitmap born_or_dead, born, dead;
1033 sbitmap_iterator sbi;
1034 bool born_p, dead_p, prev_born_p, prev_dead_p;
1036 born = sbitmap_alloc (lra_live_max_point);
1037 dead = sbitmap_alloc (lra_live_max_point);
1038 bitmap_clear (born);
1039 bitmap_clear (dead);
1040 max_regno = max_reg_num ();
1041 for (i = FIRST_PSEUDO_REGISTER; i < (unsigned) max_regno; i++)
1043 for (r = lra_reg_info[i].live_ranges; r != NULL; r = r->next)
1045 lra_assert (r->start <= r->finish);
1046 bitmap_set_bit (born, r->start);
1047 bitmap_set_bit (dead, r->finish);
1050 born_or_dead = sbitmap_alloc (lra_live_max_point);
1051 bitmap_ior (born_or_dead, born, dead);
1052 map = XCNEWVEC (int, lra_live_max_point);
1053 n = -1;
1054 prev_born_p = prev_dead_p = false;
1055 EXECUTE_IF_SET_IN_BITMAP (born_or_dead, 0, i, sbi)
1057 born_p = bitmap_bit_p (born, i);
1058 dead_p = bitmap_bit_p (dead, i);
1059 if ((prev_born_p && ! prev_dead_p && born_p && ! dead_p)
1060 || (prev_dead_p && ! prev_born_p && dead_p && ! born_p))
1062 map[i] = n;
1063 lra_point_freq[n] = MAX (lra_point_freq[n], lra_point_freq[i]);
1065 else
1067 map[i] = ++n;
1068 lra_point_freq[n] = lra_point_freq[i];
1070 prev_born_p = born_p;
1071 prev_dead_p = dead_p;
1073 sbitmap_free (born_or_dead);
1074 sbitmap_free (born);
1075 sbitmap_free (dead);
1076 n++;
1077 if (lra_dump_file != NULL)
1078 fprintf (lra_dump_file, "Compressing live ranges: from %d to %d - %d%%\n",
1079 lra_live_max_point, n, 100 * n / lra_live_max_point);
1080 if (n < lra_live_max_point)
1082 lra_live_max_point = n;
1083 for (i = FIRST_PSEUDO_REGISTER; i < (unsigned) max_regno; i++)
1085 for (prev_r = NULL, r = lra_reg_info[i].live_ranges;
1086 r != NULL;
1087 r = next_r)
1089 next_r = r->next;
1090 r->start = map[r->start];
1091 r->finish = map[r->finish];
1092 if (prev_r == NULL || prev_r->start > r->finish + 1)
1094 prev_r = r;
1095 continue;
1097 prev_r->start = r->start;
1098 prev_r->next = next_r;
1099 delete r;
1103 free (map);
1106 /* Print live ranges R to file F. */
1107 void
1108 lra_print_live_range_list (FILE *f, lra_live_range_t r)
1110 for (; r != NULL; r = r->next)
1111 fprintf (f, " [%d..%d]", r->start, r->finish);
1112 fprintf (f, "\n");
1115 DEBUG_FUNCTION void
1116 debug (lra_live_range &ref)
1118 lra_print_live_range_list (stderr, &ref);
1121 DEBUG_FUNCTION void
1122 debug (lra_live_range *ptr)
1124 if (ptr)
1125 debug (*ptr);
1126 else
1127 fprintf (stderr, "<nil>\n");
1130 /* Print live ranges R to stderr. */
1131 void
1132 lra_debug_live_range_list (lra_live_range_t r)
1134 lra_print_live_range_list (stderr, r);
1137 /* Print live ranges of pseudo REGNO to file F. */
1138 static void
1139 print_pseudo_live_ranges (FILE *f, int regno)
1141 if (lra_reg_info[regno].live_ranges == NULL)
1142 return;
1143 fprintf (f, " r%d:", regno);
1144 lra_print_live_range_list (f, lra_reg_info[regno].live_ranges);
1147 /* Print live ranges of pseudo REGNO to stderr. */
1148 void
1149 lra_debug_pseudo_live_ranges (int regno)
1151 print_pseudo_live_ranges (stderr, regno);
1154 /* Print live ranges of all pseudos to file F. */
1155 static void
1156 print_live_ranges (FILE *f)
1158 int i, max_regno;
1160 max_regno = max_reg_num ();
1161 for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
1162 print_pseudo_live_ranges (f, i);
1165 /* Print live ranges of all pseudos to stderr. */
1166 void
1167 lra_debug_live_ranges (void)
1169 print_live_ranges (stderr);
1172 /* Compress pseudo live ranges. */
1173 static void
1174 compress_live_ranges (void)
1176 remove_some_program_points_and_update_live_ranges ();
1177 if (lra_dump_file != NULL)
1179 fprintf (lra_dump_file, "Ranges after the compression:\n");
1180 print_live_ranges (lra_dump_file);
1186 /* The number of the current live range pass. */
1187 int lra_live_range_iter;
1189 /* The function creates live ranges only for memory pseudos (or for
1190 all ones if ALL_P), set up CONFLICT_HARD_REGS for the pseudos. It
1191 also does dead insn elimination if DEAD_INSN_P and global live
1192 analysis only for pseudos and only if the pseudo live info was
1193 changed on a BB border. Return TRUE if the live info was
1194 changed. */
1195 static bool
1196 lra_create_live_ranges_1 (bool all_p, bool dead_insn_p)
1198 basic_block bb;
1199 int i, hard_regno, max_regno = max_reg_num ();
1200 int curr_point;
1201 bool bb_live_change_p, have_referenced_pseudos = false;
1203 timevar_push (TV_LRA_CREATE_LIVE_RANGES);
1205 complete_info_p = all_p;
1206 if (lra_dump_file != NULL)
1207 fprintf (lra_dump_file,
1208 "\n********** Pseudo live ranges #%d: **********\n\n",
1209 ++lra_live_range_iter);
1210 memset (lra_hard_reg_usage, 0, sizeof (lra_hard_reg_usage));
1211 for (i = 0; i < max_regno; i++)
1213 lra_reg_info[i].live_ranges = NULL;
1214 CLEAR_HARD_REG_SET (lra_reg_info[i].conflict_hard_regs);
1215 lra_reg_info[i].preferred_hard_regno1 = -1;
1216 lra_reg_info[i].preferred_hard_regno2 = -1;
1217 lra_reg_info[i].preferred_hard_regno_profit1 = 0;
1218 lra_reg_info[i].preferred_hard_regno_profit2 = 0;
1219 #ifdef STACK_REGS
1220 lra_reg_info[i].no_stack_p = false;
1221 #endif
1222 /* The biggest mode is already set but its value might be to
1223 conservative because of recent transformation. Here in this
1224 file we recalculate it again as it costs practically
1225 nothing. */
1226 if (regno_reg_rtx[i] != NULL_RTX)
1227 lra_reg_info[i].biggest_mode = GET_MODE (regno_reg_rtx[i]);
1228 else
1229 lra_reg_info[i].biggest_mode = VOIDmode;
1230 lra_reg_info[i].call_p = false;
1231 if (i >= FIRST_PSEUDO_REGISTER
1232 && lra_reg_info[i].nrefs != 0)
1234 if ((hard_regno = reg_renumber[i]) >= 0)
1235 lra_hard_reg_usage[hard_regno] += lra_reg_info[i].freq;
1236 have_referenced_pseudos = true;
1239 lra_free_copies ();
1241 /* Under some circumstances, we can have functions without pseudo
1242 registers. For such functions, lra_live_max_point will be 0,
1243 see e.g. PR55604, and there's nothing more to do for us here. */
1244 if (! have_referenced_pseudos)
1246 timevar_pop (TV_LRA_CREATE_LIVE_RANGES);
1247 return false;
1250 pseudos_live = sparseset_alloc (max_regno);
1251 pseudos_live_through_calls = sparseset_alloc (max_regno);
1252 pseudos_live_through_setjumps = sparseset_alloc (max_regno);
1253 start_living = sparseset_alloc (max_regno);
1254 start_dying = sparseset_alloc (max_regno);
1255 dead_set = sparseset_alloc (max_regno);
1256 unused_set = sparseset_alloc (max_regno);
1257 curr_point = 0;
1258 point_freq_vec.create (get_max_uid () * 2);
1259 lra_point_freq = point_freq_vec.address ();
1260 int *post_order_rev_cfg = XNEWVEC (int, last_basic_block_for_fn (cfun));
1261 int n_blocks_inverted = inverted_post_order_compute (post_order_rev_cfg);
1262 lra_assert (n_blocks_inverted == n_basic_blocks_for_fn (cfun));
1263 bb_live_change_p = false;
1264 for (i = n_blocks_inverted - 1; i >= 0; --i)
1266 bb = BASIC_BLOCK_FOR_FN (cfun, post_order_rev_cfg[i]);
1267 if (bb == EXIT_BLOCK_PTR_FOR_FN (cfun) || bb
1268 == ENTRY_BLOCK_PTR_FOR_FN (cfun))
1269 continue;
1270 if (process_bb_lives (bb, curr_point, dead_insn_p))
1271 bb_live_change_p = true;
1273 if (bb_live_change_p)
1275 /* We need to clear pseudo live info as some pseudos can
1276 disappear, e.g. pseudos with used equivalences. */
1277 FOR_EACH_BB_FN (bb, cfun)
1279 bitmap_clear_range (df_get_live_in (bb), FIRST_PSEUDO_REGISTER,
1280 max_regno - FIRST_PSEUDO_REGISTER);
1281 bitmap_clear_range (df_get_live_out (bb), FIRST_PSEUDO_REGISTER,
1282 max_regno - FIRST_PSEUDO_REGISTER);
1284 /* As we did not change CFG since LRA start we can use
1285 DF-infrastructure solver to solve live data flow problem. */
1286 df_simple_dataflow
1287 (DF_BACKWARD, NULL, live_con_fun_0, live_con_fun_n,
1288 live_trans_fun, &all_blocks,
1289 df_get_postorder (DF_BACKWARD), df_get_n_blocks (DF_BACKWARD));
1290 if (lra_dump_file != NULL)
1292 fprintf (lra_dump_file,
1293 "Global pseudo live data have been updated:\n");
1294 basic_block bb;
1295 FOR_EACH_BB_FN (bb, cfun)
1297 bb_data_t bb_info = get_bb_data (bb);
1298 bitmap bb_livein = df_get_live_in (bb);
1299 bitmap bb_liveout = df_get_live_out (bb);
1301 fprintf (lra_dump_file, "\nBB %d:\n", bb->index);
1302 lra_dump_bitmap_with_title (" gen:",
1303 &bb_info->gen_pseudos, bb->index);
1304 lra_dump_bitmap_with_title (" killed:",
1305 &bb_info->killed_pseudos, bb->index);
1306 lra_dump_bitmap_with_title (" livein:", bb_livein, bb->index);
1307 lra_dump_bitmap_with_title (" liveout:", bb_liveout, bb->index);
1311 free (post_order_rev_cfg);
1312 lra_live_max_point = curr_point;
1313 if (lra_dump_file != NULL)
1314 print_live_ranges (lra_dump_file);
1315 /* Clean up. */
1316 sparseset_free (unused_set);
1317 sparseset_free (dead_set);
1318 sparseset_free (start_dying);
1319 sparseset_free (start_living);
1320 sparseset_free (pseudos_live_through_calls);
1321 sparseset_free (pseudos_live_through_setjumps);
1322 sparseset_free (pseudos_live);
1323 compress_live_ranges ();
1324 timevar_pop (TV_LRA_CREATE_LIVE_RANGES);
1325 return bb_live_change_p;
1328 /* The main entry function creates live-ranges and other live info
1329 necessary for the assignment sub-pass. It uses
1330 lra_creates_live_ranges_1 -- so read comments for the
1331 function. */
1332 void
1333 lra_create_live_ranges (bool all_p, bool dead_insn_p)
1335 if (! lra_create_live_ranges_1 (all_p, dead_insn_p))
1336 return;
1337 if (lra_dump_file != NULL)
1338 fprintf (lra_dump_file, "Live info was changed -- recalculate it\n");
1339 /* Live info was changed on a bb border. It means that some info,
1340 e.g. about conflict regs, calls crossed, and live ranges may be
1341 wrong. We need this info for allocation. So recalculate it
1342 again but without removing dead insns which can change live info
1343 again. Repetitive live range calculations are expensive therefore
1344 we stop here as we already have correct info although some
1345 improvement in rare cases could be possible on this sub-pass if
1346 we do dead insn elimination again (still the improvement may
1347 happen later). */
1348 lra_clear_live_ranges ();
1349 bool res = lra_create_live_ranges_1 (all_p, false);
1350 lra_assert (! res);
1353 /* Finish all live ranges. */
1354 void
1355 lra_clear_live_ranges (void)
1357 int i;
1359 for (i = 0; i < max_reg_num (); i++)
1360 free_live_range_list (lra_reg_info[i].live_ranges);
1361 point_freq_vec.release ();
1364 /* Initialize live ranges data once per function. */
1365 void
1366 lra_live_ranges_init (void)
1368 bitmap_initialize (&temp_bitmap, &reg_obstack);
1369 initiate_live_solver ();
1372 /* Finish live ranges data once per function. */
1373 void
1374 lra_live_ranges_finish (void)
1376 finish_live_solver ();
1377 bitmap_clear (&temp_bitmap);
1378 lra_live_range_pool.release ();