2015-10-18 Paul Thomas <pault@gcc.gnu.org>
[official-gcc.git] / gcc / lra-lives.c
blob253bc1818270685b40d2a26a067c7a292b9f80d6
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 #ifdef ENABLE_CHECKING
594 lra_reg_info[regno].call_p = true;
595 #endif
596 if (! sparseset_bit_p (pseudos_live_through_setjumps, regno))
597 return;
598 sparseset_clear_bit (pseudos_live_through_setjumps, regno);
599 /* Don't allocate pseudos that cross setjmps or any call, if this
600 function receives a nonlocal goto. */
601 SET_HARD_REG_SET (lra_reg_info[regno].conflict_hard_regs);
604 /* Process insns of the basic block BB to update pseudo live ranges,
605 pseudo hard register conflicts, and insn notes. We do it on
606 backward scan of BB insns. CURR_POINT is the program point where
607 BB ends. The function updates this counter and returns in
608 CURR_POINT the program point where BB starts. The function also
609 does local live info updates and can delete the dead insns if
610 DEAD_INSN_P. It returns true if pseudo live info was
611 changed at the BB start. */
612 static bool
613 process_bb_lives (basic_block bb, int &curr_point, bool dead_insn_p)
615 int i, regno, freq;
616 unsigned int j;
617 bitmap_iterator bi;
618 bitmap reg_live_out;
619 unsigned int px;
620 rtx_insn *next;
621 rtx link, *link_loc;
622 bool need_curr_point_incr;
624 reg_live_out = df_get_live_out (bb);
625 sparseset_clear (pseudos_live);
626 sparseset_clear (pseudos_live_through_calls);
627 sparseset_clear (pseudos_live_through_setjumps);
628 REG_SET_TO_HARD_REG_SET (hard_regs_live, reg_live_out);
629 AND_COMPL_HARD_REG_SET (hard_regs_live, eliminable_regset);
630 EXECUTE_IF_SET_IN_BITMAP (reg_live_out, FIRST_PSEUDO_REGISTER, j, bi)
631 mark_pseudo_live (j, curr_point);
633 bb_gen_pseudos = &get_bb_data (bb)->gen_pseudos;
634 bb_killed_pseudos = &get_bb_data (bb)->killed_pseudos;
635 bitmap_clear (bb_gen_pseudos);
636 bitmap_clear (bb_killed_pseudos);
637 freq = REG_FREQ_FROM_BB (bb);
639 if (lra_dump_file != NULL)
640 fprintf (lra_dump_file, " BB %d\n", bb->index);
642 /* Scan the code of this basic block, noting which pseudos and hard
643 regs are born or die.
645 Note that this loop treats uninitialized values as live until the
646 beginning of the block. For example, if an instruction uses
647 (reg:DI foo), and only (subreg:SI (reg:DI foo) 0) is ever set,
648 FOO will remain live until the beginning of the block. Likewise
649 if FOO is not set at all. This is unnecessarily pessimistic, but
650 it probably doesn't matter much in practice. */
651 FOR_BB_INSNS_REVERSE_SAFE (bb, curr_insn, next)
653 bool call_p;
654 int dst_regno, src_regno;
655 rtx set;
656 struct lra_insn_reg *reg;
658 if (!NONDEBUG_INSN_P (curr_insn))
659 continue;
661 curr_id = lra_get_insn_recog_data (curr_insn);
662 curr_static_id = curr_id->insn_static_data;
663 if (lra_dump_file != NULL)
664 fprintf (lra_dump_file, " Insn %u: point = %d\n",
665 INSN_UID (curr_insn), curr_point);
667 set = single_set (curr_insn);
669 if (dead_insn_p && set != NULL_RTX
670 && REG_P (SET_DEST (set)) && REGNO (SET_DEST (set)) >= FIRST_PSEUDO_REGISTER
671 && find_reg_note (curr_insn, REG_EH_REGION, NULL_RTX) == NULL_RTX
672 && ! may_trap_p (PATTERN (curr_insn))
673 /* Don't do premature remove of pic offset pseudo as we can
674 start to use it after some reload generation. */
675 && (pic_offset_table_rtx == NULL_RTX
676 || pic_offset_table_rtx != SET_DEST (set)))
678 bool remove_p = true;
680 for (reg = curr_id->regs; reg != NULL; reg = reg->next)
681 if (reg->type != OP_IN && sparseset_bit_p (pseudos_live, reg->regno))
683 remove_p = false;
684 break;
686 for (reg = curr_static_id->hard_regs; reg != NULL; reg = reg->next)
687 if (reg->type != OP_IN)
689 remove_p = false;
690 break;
692 if (remove_p && ! volatile_refs_p (PATTERN (curr_insn)))
694 dst_regno = REGNO (SET_DEST (set));
695 if (lra_dump_file != NULL)
696 fprintf (lra_dump_file, " Deleting dead insn %u\n",
697 INSN_UID (curr_insn));
698 lra_set_insn_deleted (curr_insn);
699 if (lra_reg_info[dst_regno].nrefs == 0)
701 /* There might be some debug insns with the pseudo. */
702 unsigned int uid;
703 rtx_insn *insn;
705 bitmap_copy (&temp_bitmap, &lra_reg_info[dst_regno].insn_bitmap);
706 EXECUTE_IF_SET_IN_BITMAP (&temp_bitmap, 0, uid, bi)
708 insn = lra_insn_recog_data[uid]->insn;
709 lra_substitute_pseudo_within_insn (insn, dst_regno,
710 SET_SRC (set), true);
711 lra_update_insn_regno_info (insn);
714 continue;
718 /* Update max ref width and hard reg usage. */
719 for (reg = curr_id->regs; reg != NULL; reg = reg->next)
720 if (reg->regno >= FIRST_PSEUDO_REGISTER
721 && (GET_MODE_SIZE (reg->biggest_mode)
722 > GET_MODE_SIZE (lra_reg_info[reg->regno].biggest_mode)))
723 lra_reg_info[reg->regno].biggest_mode = reg->biggest_mode;
724 else if (reg->regno < FIRST_PSEUDO_REGISTER)
725 lra_hard_reg_usage[reg->regno] += freq;
727 call_p = CALL_P (curr_insn);
728 src_regno = (set != NULL_RTX && REG_P (SET_SRC (set))
729 ? REGNO (SET_SRC (set)) : -1);
730 dst_regno = (set != NULL_RTX && REG_P (SET_DEST (set))
731 ? REGNO (SET_DEST (set)) : -1);
732 if (complete_info_p
733 && src_regno >= 0 && dst_regno >= 0
734 /* Check that source regno does not conflict with
735 destination regno to exclude most impossible
736 preferences. */
737 && (((src_regno >= FIRST_PSEUDO_REGISTER
738 && (! sparseset_bit_p (pseudos_live, src_regno)
739 || (dst_regno >= FIRST_PSEUDO_REGISTER
740 && lra_reg_val_equal_p (src_regno,
741 lra_reg_info[dst_regno].val,
742 lra_reg_info[dst_regno].offset))))
743 || (src_regno < FIRST_PSEUDO_REGISTER
744 && ! TEST_HARD_REG_BIT (hard_regs_live, src_regno)))
745 /* It might be 'inheritance pseudo <- reload pseudo'. */
746 || (src_regno >= lra_constraint_new_regno_start
747 && dst_regno >= lra_constraint_new_regno_start
748 /* Remember to skip special cases where src/dest regnos are
749 the same, e.g. insn SET pattern has matching constraints
750 like =r,0. */
751 && src_regno != dst_regno)))
753 int hard_regno = -1, regno = -1;
755 if (dst_regno >= lra_constraint_new_regno_start
756 && src_regno >= lra_constraint_new_regno_start)
758 /* It might be still an original (non-reload) insn with
759 one unused output and a constraint requiring to use
760 the same reg for input/output operands. In this case
761 dst_regno and src_regno have the same value, we don't
762 need a misleading copy for this case. */
763 if (dst_regno != src_regno)
764 lra_create_copy (dst_regno, src_regno, freq);
766 else if (dst_regno >= lra_constraint_new_regno_start)
768 if ((hard_regno = src_regno) >= FIRST_PSEUDO_REGISTER)
769 hard_regno = reg_renumber[src_regno];
770 regno = dst_regno;
772 else if (src_regno >= lra_constraint_new_regno_start)
774 if ((hard_regno = dst_regno) >= FIRST_PSEUDO_REGISTER)
775 hard_regno = reg_renumber[dst_regno];
776 regno = src_regno;
778 if (regno >= 0 && hard_regno >= 0)
779 lra_setup_reload_pseudo_preferenced_hard_reg
780 (regno, hard_regno, freq);
783 sparseset_clear (start_living);
785 /* Try to avoid unnecessary program point increments, this saves
786 a lot of time in remove_some_program_points_and_update_live_ranges.
787 We only need an increment if something becomes live or dies at this
788 program point. */
789 need_curr_point_incr = false;
791 /* Mark each defined value as live. We need to do this for
792 unused values because they still conflict with quantities
793 that are live at the time of the definition. */
794 for (reg = curr_id->regs; reg != NULL; reg = reg->next)
795 if (reg->type != OP_IN)
797 need_curr_point_incr
798 |= mark_regno_live (reg->regno, reg->biggest_mode,
799 curr_point);
800 check_pseudos_live_through_calls (reg->regno);
803 for (reg = curr_static_id->hard_regs; reg != NULL; reg = reg->next)
804 if (reg->type != OP_IN)
805 make_hard_regno_born (reg->regno, false);
807 if (curr_id->arg_hard_regs != NULL)
808 for (i = 0; (regno = curr_id->arg_hard_regs[i]) >= 0; i++)
809 if (regno >= FIRST_PSEUDO_REGISTER)
810 /* It is a clobber. */
811 make_hard_regno_born (regno - FIRST_PSEUDO_REGISTER, false);
813 sparseset_copy (unused_set, start_living);
815 sparseset_clear (start_dying);
817 /* See which defined values die here. */
818 for (reg = curr_id->regs; reg != NULL; reg = reg->next)
819 if (reg->type == OP_OUT && ! reg->early_clobber && ! reg->subreg_p)
820 need_curr_point_incr
821 |= mark_regno_dead (reg->regno, reg->biggest_mode,
822 curr_point);
824 for (reg = curr_static_id->hard_regs; reg != NULL; reg = reg->next)
825 if (reg->type == OP_OUT && ! reg->early_clobber && ! reg->subreg_p)
826 make_hard_regno_dead (reg->regno);
828 if (curr_id->arg_hard_regs != NULL)
829 for (i = 0; (regno = curr_id->arg_hard_regs[i]) >= 0; i++)
830 if (regno >= FIRST_PSEUDO_REGISTER)
831 /* It is a clobber. */
832 make_hard_regno_dead (regno - FIRST_PSEUDO_REGISTER);
834 if (call_p)
836 if (flag_ipa_ra)
838 HARD_REG_SET this_call_used_reg_set;
839 get_call_reg_set_usage (curr_insn, &this_call_used_reg_set,
840 call_used_reg_set);
842 EXECUTE_IF_SET_IN_SPARSESET (pseudos_live, j)
843 IOR_HARD_REG_SET (lra_reg_info[j].actual_call_used_reg_set,
844 this_call_used_reg_set);
847 sparseset_ior (pseudos_live_through_calls,
848 pseudos_live_through_calls, pseudos_live);
849 if (cfun->has_nonlocal_label
850 || find_reg_note (curr_insn, REG_SETJMP,
851 NULL_RTX) != NULL_RTX)
852 sparseset_ior (pseudos_live_through_setjumps,
853 pseudos_live_through_setjumps, pseudos_live);
856 /* Increment the current program point if we must. */
857 if (need_curr_point_incr)
858 next_program_point (curr_point, freq);
860 sparseset_clear (start_living);
862 need_curr_point_incr = false;
864 /* Mark each used value as live. */
865 for (reg = curr_id->regs; reg != NULL; reg = reg->next)
866 if (reg->type == OP_IN)
868 need_curr_point_incr
869 |= mark_regno_live (reg->regno, reg->biggest_mode,
870 curr_point);
871 check_pseudos_live_through_calls (reg->regno);
874 for (reg = curr_static_id->hard_regs; reg != NULL; reg = reg->next)
875 if (reg->type == OP_IN)
876 make_hard_regno_born (reg->regno, false);
878 if (curr_id->arg_hard_regs != NULL)
879 /* Make argument hard registers live. Don't create conflict
880 of used REAL_PIC_OFFSET_TABLE_REGNUM and the pic pseudo. */
881 for (i = 0; (regno = curr_id->arg_hard_regs[i]) >= 0; i++)
882 if (regno < FIRST_PSEUDO_REGISTER)
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
958 && has_abnormal_call_or_eh_pred_edge_p (bb))
959 for (px = 0; px < FIRST_PSEUDO_REGISTER; px++)
960 if (call_used_regs[px]
961 #ifdef REAL_PIC_OFFSET_TABLE_REGNUM
962 /* We should create a conflict of PIC pseudo with PIC
963 hard reg as PIC hard reg can have a wrong value after
964 jump described by the abnormal edge. In this case we
965 can not allocate PIC hard reg to PIC pseudo as PIC
966 pseudo will also have a wrong value. */
967 || (px == REAL_PIC_OFFSET_TABLE_REGNUM
968 && pic_offset_table_rtx != NULL_RTX
969 && REGNO (pic_offset_table_rtx) >= FIRST_PSEUDO_REGISTER)
970 #endif
972 make_hard_regno_born (px, false);
975 bool live_change_p = false;
976 /* Check if bb border live info was changed. */
977 unsigned int live_pseudos_num = 0;
978 EXECUTE_IF_SET_IN_BITMAP (df_get_live_in (bb),
979 FIRST_PSEUDO_REGISTER, j, bi)
981 live_pseudos_num++;
982 if (! sparseset_bit_p (pseudos_live, j))
984 live_change_p = true;
985 if (lra_dump_file != NULL)
986 fprintf (lra_dump_file,
987 " r%d is removed as live at bb%d start\n", j, bb->index);
988 break;
991 if (! live_change_p
992 && sparseset_cardinality (pseudos_live) != live_pseudos_num)
994 live_change_p = true;
995 if (lra_dump_file != NULL)
996 EXECUTE_IF_SET_IN_SPARSESET (pseudos_live, j)
997 if (! bitmap_bit_p (df_get_live_in (bb), j))
998 fprintf (lra_dump_file,
999 " r%d is added to live at bb%d start\n", j, bb->index);
1001 /* See if we'll need an increment at the end of this basic block.
1002 An increment is needed if the PSEUDOS_LIVE set is not empty,
1003 to make sure the finish points are set up correctly. */
1004 need_curr_point_incr = (sparseset_cardinality (pseudos_live) > 0);
1006 EXECUTE_IF_SET_IN_SPARSESET (pseudos_live, i)
1007 mark_pseudo_dead (i, curr_point);
1009 EXECUTE_IF_SET_IN_BITMAP (df_get_live_in (bb), FIRST_PSEUDO_REGISTER, j, bi)
1011 if (sparseset_cardinality (pseudos_live_through_calls) == 0)
1012 break;
1013 if (sparseset_bit_p (pseudos_live_through_calls, j))
1014 check_pseudos_live_through_calls (j);
1017 if (need_curr_point_incr)
1018 next_program_point (curr_point, freq);
1020 return live_change_p;
1023 /* Compress pseudo live ranges by removing program points where
1024 nothing happens. Complexity of many algorithms in LRA is linear
1025 function of program points number. To speed up the code we try to
1026 minimize the number of the program points here. */
1027 static void
1028 remove_some_program_points_and_update_live_ranges (void)
1030 unsigned i;
1031 int n, max_regno;
1032 int *map;
1033 lra_live_range_t r, prev_r, next_r;
1034 sbitmap born_or_dead, born, dead;
1035 sbitmap_iterator sbi;
1036 bool born_p, dead_p, prev_born_p, prev_dead_p;
1038 born = sbitmap_alloc (lra_live_max_point);
1039 dead = sbitmap_alloc (lra_live_max_point);
1040 bitmap_clear (born);
1041 bitmap_clear (dead);
1042 max_regno = max_reg_num ();
1043 for (i = FIRST_PSEUDO_REGISTER; i < (unsigned) max_regno; i++)
1045 for (r = lra_reg_info[i].live_ranges; r != NULL; r = r->next)
1047 lra_assert (r->start <= r->finish);
1048 bitmap_set_bit (born, r->start);
1049 bitmap_set_bit (dead, r->finish);
1052 born_or_dead = sbitmap_alloc (lra_live_max_point);
1053 bitmap_ior (born_or_dead, born, dead);
1054 map = XCNEWVEC (int, lra_live_max_point);
1055 n = -1;
1056 prev_born_p = prev_dead_p = false;
1057 EXECUTE_IF_SET_IN_BITMAP (born_or_dead, 0, i, sbi)
1059 born_p = bitmap_bit_p (born, i);
1060 dead_p = bitmap_bit_p (dead, i);
1061 if ((prev_born_p && ! prev_dead_p && born_p && ! dead_p)
1062 || (prev_dead_p && ! prev_born_p && dead_p && ! born_p))
1064 map[i] = n;
1065 lra_point_freq[n] = MAX (lra_point_freq[n], lra_point_freq[i]);
1067 else
1069 map[i] = ++n;
1070 lra_point_freq[n] = lra_point_freq[i];
1072 prev_born_p = born_p;
1073 prev_dead_p = dead_p;
1075 sbitmap_free (born_or_dead);
1076 sbitmap_free (born);
1077 sbitmap_free (dead);
1078 n++;
1079 if (lra_dump_file != NULL)
1080 fprintf (lra_dump_file, "Compressing live ranges: from %d to %d - %d%%\n",
1081 lra_live_max_point, n, 100 * n / lra_live_max_point);
1082 if (n < lra_live_max_point)
1084 lra_live_max_point = n;
1085 for (i = FIRST_PSEUDO_REGISTER; i < (unsigned) max_regno; i++)
1087 for (prev_r = NULL, r = lra_reg_info[i].live_ranges;
1088 r != NULL;
1089 r = next_r)
1091 next_r = r->next;
1092 r->start = map[r->start];
1093 r->finish = map[r->finish];
1094 if (prev_r == NULL || prev_r->start > r->finish + 1)
1096 prev_r = r;
1097 continue;
1099 prev_r->start = r->start;
1100 prev_r->next = next_r;
1101 delete r;
1105 free (map);
1108 /* Print live ranges R to file F. */
1109 void
1110 lra_print_live_range_list (FILE *f, lra_live_range_t r)
1112 for (; r != NULL; r = r->next)
1113 fprintf (f, " [%d..%d]", r->start, r->finish);
1114 fprintf (f, "\n");
1117 DEBUG_FUNCTION void
1118 debug (lra_live_range &ref)
1120 lra_print_live_range_list (stderr, &ref);
1123 DEBUG_FUNCTION void
1124 debug (lra_live_range *ptr)
1126 if (ptr)
1127 debug (*ptr);
1128 else
1129 fprintf (stderr, "<nil>\n");
1132 /* Print live ranges R to stderr. */
1133 void
1134 lra_debug_live_range_list (lra_live_range_t r)
1136 lra_print_live_range_list (stderr, r);
1139 /* Print live ranges of pseudo REGNO to file F. */
1140 static void
1141 print_pseudo_live_ranges (FILE *f, int regno)
1143 if (lra_reg_info[regno].live_ranges == NULL)
1144 return;
1145 fprintf (f, " r%d:", regno);
1146 lra_print_live_range_list (f, lra_reg_info[regno].live_ranges);
1149 /* Print live ranges of pseudo REGNO to stderr. */
1150 void
1151 lra_debug_pseudo_live_ranges (int regno)
1153 print_pseudo_live_ranges (stderr, regno);
1156 /* Print live ranges of all pseudos to file F. */
1157 static void
1158 print_live_ranges (FILE *f)
1160 int i, max_regno;
1162 max_regno = max_reg_num ();
1163 for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
1164 print_pseudo_live_ranges (f, i);
1167 /* Print live ranges of all pseudos to stderr. */
1168 void
1169 lra_debug_live_ranges (void)
1171 print_live_ranges (stderr);
1174 /* Compress pseudo live ranges. */
1175 static void
1176 compress_live_ranges (void)
1178 remove_some_program_points_and_update_live_ranges ();
1179 if (lra_dump_file != NULL)
1181 fprintf (lra_dump_file, "Ranges after the compression:\n");
1182 print_live_ranges (lra_dump_file);
1188 /* The number of the current live range pass. */
1189 int lra_live_range_iter;
1191 /* The function creates live ranges only for memory pseudos (or for
1192 all ones if ALL_P), set up CONFLICT_HARD_REGS for the pseudos. It
1193 also does dead insn elimination if DEAD_INSN_P and global live
1194 analysis only for pseudos and only if the pseudo live info was
1195 changed on a BB border. Return TRUE if the live info was
1196 changed. */
1197 static bool
1198 lra_create_live_ranges_1 (bool all_p, bool dead_insn_p)
1200 basic_block bb;
1201 int i, hard_regno, max_regno = max_reg_num ();
1202 int curr_point;
1203 bool bb_live_change_p, have_referenced_pseudos = false;
1205 timevar_push (TV_LRA_CREATE_LIVE_RANGES);
1207 complete_info_p = all_p;
1208 if (lra_dump_file != NULL)
1209 fprintf (lra_dump_file,
1210 "\n********** Pseudo live ranges #%d: **********\n\n",
1211 ++lra_live_range_iter);
1212 memset (lra_hard_reg_usage, 0, sizeof (lra_hard_reg_usage));
1213 for (i = 0; i < max_regno; i++)
1215 lra_reg_info[i].live_ranges = NULL;
1216 CLEAR_HARD_REG_SET (lra_reg_info[i].conflict_hard_regs);
1217 lra_reg_info[i].preferred_hard_regno1 = -1;
1218 lra_reg_info[i].preferred_hard_regno2 = -1;
1219 lra_reg_info[i].preferred_hard_regno_profit1 = 0;
1220 lra_reg_info[i].preferred_hard_regno_profit2 = 0;
1221 #ifdef STACK_REGS
1222 lra_reg_info[i].no_stack_p = false;
1223 #endif
1224 /* The biggest mode is already set but its value might be to
1225 conservative because of recent transformation. Here in this
1226 file we recalculate it again as it costs practically
1227 nothing. */
1228 if (regno_reg_rtx[i] != NULL_RTX)
1229 lra_reg_info[i].biggest_mode = GET_MODE (regno_reg_rtx[i]);
1230 else
1231 lra_reg_info[i].biggest_mode = VOIDmode;
1232 #ifdef ENABLE_CHECKING
1233 lra_reg_info[i].call_p = false;
1234 #endif
1235 if (i >= FIRST_PSEUDO_REGISTER
1236 && lra_reg_info[i].nrefs != 0)
1238 if ((hard_regno = reg_renumber[i]) >= 0)
1239 lra_hard_reg_usage[hard_regno] += lra_reg_info[i].freq;
1240 have_referenced_pseudos = true;
1243 lra_free_copies ();
1245 /* Under some circumstances, we can have functions without pseudo
1246 registers. For such functions, lra_live_max_point will be 0,
1247 see e.g. PR55604, and there's nothing more to do for us here. */
1248 if (! have_referenced_pseudos)
1250 timevar_pop (TV_LRA_CREATE_LIVE_RANGES);
1251 return false;
1254 pseudos_live = sparseset_alloc (max_regno);
1255 pseudos_live_through_calls = sparseset_alloc (max_regno);
1256 pseudos_live_through_setjumps = sparseset_alloc (max_regno);
1257 start_living = sparseset_alloc (max_regno);
1258 start_dying = sparseset_alloc (max_regno);
1259 dead_set = sparseset_alloc (max_regno);
1260 unused_set = sparseset_alloc (max_regno);
1261 curr_point = 0;
1262 point_freq_vec.create (get_max_uid () * 2);
1263 lra_point_freq = point_freq_vec.address ();
1264 int *post_order_rev_cfg = XNEWVEC (int, last_basic_block_for_fn (cfun));
1265 int n_blocks_inverted = inverted_post_order_compute (post_order_rev_cfg);
1266 lra_assert (n_blocks_inverted == n_basic_blocks_for_fn (cfun));
1267 bb_live_change_p = false;
1268 for (i = n_blocks_inverted - 1; i >= 0; --i)
1270 bb = BASIC_BLOCK_FOR_FN (cfun, post_order_rev_cfg[i]);
1271 if (bb == EXIT_BLOCK_PTR_FOR_FN (cfun) || bb
1272 == ENTRY_BLOCK_PTR_FOR_FN (cfun))
1273 continue;
1274 if (process_bb_lives (bb, curr_point, dead_insn_p))
1275 bb_live_change_p = true;
1277 if (bb_live_change_p)
1279 /* We need to clear pseudo live info as some pseudos can
1280 disappear, e.g. pseudos with used equivalences. */
1281 FOR_EACH_BB_FN (bb, cfun)
1283 bitmap_clear_range (df_get_live_in (bb), FIRST_PSEUDO_REGISTER,
1284 max_regno - FIRST_PSEUDO_REGISTER);
1285 bitmap_clear_range (df_get_live_out (bb), FIRST_PSEUDO_REGISTER,
1286 max_regno - FIRST_PSEUDO_REGISTER);
1288 /* As we did not change CFG since LRA start we can use
1289 DF-infrastructure solver to solve live data flow problem. */
1290 df_simple_dataflow
1291 (DF_BACKWARD, NULL, live_con_fun_0, live_con_fun_n,
1292 live_trans_fun, &all_blocks,
1293 df_get_postorder (DF_BACKWARD), df_get_n_blocks (DF_BACKWARD));
1294 if (lra_dump_file != NULL)
1296 fprintf (lra_dump_file,
1297 "Global pseudo live data have been updated:\n");
1298 basic_block bb;
1299 FOR_EACH_BB_FN (bb, cfun)
1301 bb_data_t bb_info = get_bb_data (bb);
1302 bitmap bb_livein = df_get_live_in (bb);
1303 bitmap bb_liveout = df_get_live_out (bb);
1305 fprintf (lra_dump_file, "\nBB %d:\n", bb->index);
1306 lra_dump_bitmap_with_title (" gen:",
1307 &bb_info->gen_pseudos, bb->index);
1308 lra_dump_bitmap_with_title (" killed:",
1309 &bb_info->killed_pseudos, bb->index);
1310 lra_dump_bitmap_with_title (" livein:", bb_livein, bb->index);
1311 lra_dump_bitmap_with_title (" liveout:", bb_liveout, bb->index);
1315 free (post_order_rev_cfg);
1316 lra_live_max_point = curr_point;
1317 if (lra_dump_file != NULL)
1318 print_live_ranges (lra_dump_file);
1319 /* Clean up. */
1320 sparseset_free (unused_set);
1321 sparseset_free (dead_set);
1322 sparseset_free (start_dying);
1323 sparseset_free (start_living);
1324 sparseset_free (pseudos_live_through_calls);
1325 sparseset_free (pseudos_live_through_setjumps);
1326 sparseset_free (pseudos_live);
1327 compress_live_ranges ();
1328 timevar_pop (TV_LRA_CREATE_LIVE_RANGES);
1329 return bb_live_change_p;
1332 /* The main entry function creates live-ranges and other live info
1333 necessary for the assignment sub-pass. It uses
1334 lra_creates_live_ranges_1 -- so read comments for the
1335 function. */
1336 void
1337 lra_create_live_ranges (bool all_p, bool dead_insn_p)
1339 if (! lra_create_live_ranges_1 (all_p, dead_insn_p))
1340 return;
1341 if (lra_dump_file != NULL)
1342 fprintf (lra_dump_file, "Live info was changed -- recalculate it\n");
1343 /* Live info was changed on a bb border. It means that some info,
1344 e.g. about conflict regs, calls crossed, and live ranges may be
1345 wrong. We need this info for allocation. So recalculate it
1346 again but without removing dead insns which can change live info
1347 again. Repetitive live range calculations are expensive therefore
1348 we stop here as we already have correct info although some
1349 improvement in rare cases could be possible on this sub-pass if
1350 we do dead insn elimination again (still the improvement may
1351 happen later). */
1352 lra_clear_live_ranges ();
1353 bool res = lra_create_live_ranges_1 (all_p, false);
1354 lra_assert (! res);
1357 /* Finish all live ranges. */
1358 void
1359 lra_clear_live_ranges (void)
1361 int i;
1363 for (i = 0; i < max_reg_num (); i++)
1364 free_live_range_list (lra_reg_info[i].live_ranges);
1365 point_freq_vec.release ();
1368 /* Initialize live ranges data once per function. */
1369 void
1370 lra_live_ranges_init (void)
1372 bitmap_initialize (&temp_bitmap, &reg_obstack);
1373 initiate_live_solver ();
1376 /* Finish live ranges data once per function. */
1377 void
1378 lra_live_ranges_finish (void)
1380 finish_live_solver ();
1381 bitmap_clear (&temp_bitmap);
1382 lra_live_range_pool.release ();