/cp
[official-gcc.git] / gcc / lra-lives.c
blob8b8636875642b8beec19ba118acb94d033ab8a6d
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 pool_allocator <lra_live_range> lra_live_range::pool ("live ranges", 100);
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 /* Return true when one of the predecessor edges of BB is marked with
512 EDGE_ABNORMAL_CALL or EDGE_EH. */
513 static bool
514 bb_has_abnormal_call_pred (basic_block bb)
516 edge e;
517 edge_iterator ei;
519 FOR_EACH_EDGE (e, ei, bb->preds)
521 if (e->flags & (EDGE_ABNORMAL_CALL | EDGE_EH))
522 return true;
524 return false;
527 /* Vec containing execution frequencies of program points. */
528 static vec<int> point_freq_vec;
530 /* The start of the above vector elements. */
531 int *lra_point_freq;
533 /* Increment the current program point POINT to the next point which has
534 execution frequency FREQ. */
535 static void
536 next_program_point (int &point, int freq)
538 point_freq_vec.safe_push (freq);
539 lra_point_freq = point_freq_vec.address ();
540 point++;
543 /* Update the preference of HARD_REGNO for pseudo REGNO by PROFIT. */
544 void
545 lra_setup_reload_pseudo_preferenced_hard_reg (int regno,
546 int hard_regno, int profit)
548 lra_assert (regno >= lra_constraint_new_regno_start);
549 if (lra_reg_info[regno].preferred_hard_regno1 == hard_regno)
550 lra_reg_info[regno].preferred_hard_regno_profit1 += profit;
551 else if (lra_reg_info[regno].preferred_hard_regno2 == hard_regno)
552 lra_reg_info[regno].preferred_hard_regno_profit2 += profit;
553 else if (lra_reg_info[regno].preferred_hard_regno1 < 0)
555 lra_reg_info[regno].preferred_hard_regno1 = hard_regno;
556 lra_reg_info[regno].preferred_hard_regno_profit1 = profit;
558 else if (lra_reg_info[regno].preferred_hard_regno2 < 0
559 || profit > lra_reg_info[regno].preferred_hard_regno_profit2)
561 lra_reg_info[regno].preferred_hard_regno2 = hard_regno;
562 lra_reg_info[regno].preferred_hard_regno_profit2 = profit;
564 else
565 return;
566 /* Keep the 1st hard regno as more profitable. */
567 if (lra_reg_info[regno].preferred_hard_regno1 >= 0
568 && lra_reg_info[regno].preferred_hard_regno2 >= 0
569 && (lra_reg_info[regno].preferred_hard_regno_profit2
570 > lra_reg_info[regno].preferred_hard_regno_profit1))
572 std::swap (lra_reg_info[regno].preferred_hard_regno1,
573 lra_reg_info[regno].preferred_hard_regno2);
574 std::swap (lra_reg_info[regno].preferred_hard_regno_profit1,
575 lra_reg_info[regno].preferred_hard_regno_profit2);
577 if (lra_dump_file != NULL)
579 if ((hard_regno = lra_reg_info[regno].preferred_hard_regno1) >= 0)
580 fprintf (lra_dump_file,
581 " Hard reg %d is preferable by r%d with profit %d\n",
582 hard_regno, regno,
583 lra_reg_info[regno].preferred_hard_regno_profit1);
584 if ((hard_regno = lra_reg_info[regno].preferred_hard_regno2) >= 0)
585 fprintf (lra_dump_file,
586 " Hard reg %d is preferable by r%d with profit %d\n",
587 hard_regno, regno,
588 lra_reg_info[regno].preferred_hard_regno_profit2);
592 /* Check that REGNO living through calls and setjumps, set up conflict
593 regs, and clear corresponding bits in PSEUDOS_LIVE_THROUGH_CALLS and
594 PSEUDOS_LIVE_THROUGH_SETJUMPS. */
595 static inline void
596 check_pseudos_live_through_calls (int regno)
598 int hr;
600 if (! sparseset_bit_p (pseudos_live_through_calls, regno))
601 return;
602 sparseset_clear_bit (pseudos_live_through_calls, regno);
603 IOR_HARD_REG_SET (lra_reg_info[regno].conflict_hard_regs,
604 call_used_reg_set);
606 for (hr = 0; hr < FIRST_PSEUDO_REGISTER; hr++)
607 if (HARD_REGNO_CALL_PART_CLOBBERED (hr, PSEUDO_REGNO_MODE (regno)))
608 SET_HARD_REG_BIT (lra_reg_info[regno].conflict_hard_regs, hr);
609 #ifdef ENABLE_CHECKING
610 lra_reg_info[regno].call_p = true;
611 #endif
612 if (! sparseset_bit_p (pseudos_live_through_setjumps, regno))
613 return;
614 sparseset_clear_bit (pseudos_live_through_setjumps, regno);
615 /* Don't allocate pseudos that cross setjmps or any call, if this
616 function receives a nonlocal goto. */
617 SET_HARD_REG_SET (lra_reg_info[regno].conflict_hard_regs);
620 /* Process insns of the basic block BB to update pseudo live ranges,
621 pseudo hard register conflicts, and insn notes. We do it on
622 backward scan of BB insns. CURR_POINT is the program point where
623 BB ends. The function updates this counter and returns in
624 CURR_POINT the program point where BB starts. The function also
625 does local live info updates and can delete the dead insns if
626 DEAD_INSN_P. It returns true if pseudo live info was
627 changed at the BB start. */
628 static bool
629 process_bb_lives (basic_block bb, int &curr_point, bool dead_insn_p)
631 int i, regno, freq;
632 unsigned int j;
633 bitmap_iterator bi;
634 bitmap reg_live_out;
635 unsigned int px;
636 rtx_insn *next;
637 rtx link, *link_loc;
638 bool need_curr_point_incr;
640 reg_live_out = df_get_live_out (bb);
641 sparseset_clear (pseudos_live);
642 sparseset_clear (pseudos_live_through_calls);
643 sparseset_clear (pseudos_live_through_setjumps);
644 REG_SET_TO_HARD_REG_SET (hard_regs_live, reg_live_out);
645 AND_COMPL_HARD_REG_SET (hard_regs_live, eliminable_regset);
646 EXECUTE_IF_SET_IN_BITMAP (reg_live_out, FIRST_PSEUDO_REGISTER, j, bi)
647 mark_pseudo_live (j, curr_point);
649 bb_gen_pseudos = &get_bb_data (bb)->gen_pseudos;
650 bb_killed_pseudos = &get_bb_data (bb)->killed_pseudos;
651 bitmap_clear (bb_gen_pseudos);
652 bitmap_clear (bb_killed_pseudos);
653 freq = REG_FREQ_FROM_BB (bb);
655 if (lra_dump_file != NULL)
656 fprintf (lra_dump_file, " BB %d\n", bb->index);
658 /* Scan the code of this basic block, noting which pseudos and hard
659 regs are born or die.
661 Note that this loop treats uninitialized values as live until the
662 beginning of the block. For example, if an instruction uses
663 (reg:DI foo), and only (subreg:SI (reg:DI foo) 0) is ever set,
664 FOO will remain live until the beginning of the block. Likewise
665 if FOO is not set at all. This is unnecessarily pessimistic, but
666 it probably doesn't matter much in practice. */
667 FOR_BB_INSNS_REVERSE_SAFE (bb, curr_insn, next)
669 bool call_p;
670 int dst_regno, src_regno;
671 rtx set;
672 struct lra_insn_reg *reg;
674 if (!NONDEBUG_INSN_P (curr_insn))
675 continue;
677 curr_id = lra_get_insn_recog_data (curr_insn);
678 curr_static_id = curr_id->insn_static_data;
679 if (lra_dump_file != NULL)
680 fprintf (lra_dump_file, " Insn %u: point = %d\n",
681 INSN_UID (curr_insn), curr_point);
683 set = single_set (curr_insn);
685 if (dead_insn_p && set != NULL_RTX
686 && REG_P (SET_DEST (set)) && REGNO (SET_DEST (set)) >= FIRST_PSEUDO_REGISTER
687 && find_reg_note (curr_insn, REG_EH_REGION, NULL_RTX) == NULL_RTX
688 && ! may_trap_p (PATTERN (curr_insn))
689 /* Don't do premature remove of pic offset pseudo as we can
690 start to use it after some reload generation. */
691 && (pic_offset_table_rtx == NULL_RTX
692 || pic_offset_table_rtx != SET_DEST (set)))
694 bool remove_p = true;
696 for (reg = curr_id->regs; reg != NULL; reg = reg->next)
697 if (reg->type != OP_IN && sparseset_bit_p (pseudos_live, reg->regno))
699 remove_p = false;
700 break;
702 for (reg = curr_static_id->hard_regs; reg != NULL; reg = reg->next)
703 if (reg->type != OP_IN)
705 remove_p = false;
706 break;
708 if (remove_p && ! volatile_refs_p (PATTERN (curr_insn)))
710 dst_regno = REGNO (SET_DEST (set));
711 if (lra_dump_file != NULL)
712 fprintf (lra_dump_file, " Deleting dead insn %u\n",
713 INSN_UID (curr_insn));
714 lra_set_insn_deleted (curr_insn);
715 if (lra_reg_info[dst_regno].nrefs == 0)
717 /* There might be some debug insns with the pseudo. */
718 unsigned int uid;
719 rtx_insn *insn;
721 bitmap_copy (&temp_bitmap, &lra_reg_info[dst_regno].insn_bitmap);
722 EXECUTE_IF_SET_IN_BITMAP (&temp_bitmap, 0, uid, bi)
724 insn = lra_insn_recog_data[uid]->insn;
725 lra_substitute_pseudo_within_insn (insn, dst_regno,
726 SET_SRC (set), true);
727 lra_update_insn_regno_info (insn);
730 continue;
734 /* Update max ref width and hard reg usage. */
735 for (reg = curr_id->regs; reg != NULL; reg = reg->next)
736 if (reg->regno >= FIRST_PSEUDO_REGISTER
737 && (GET_MODE_SIZE (reg->biggest_mode)
738 > GET_MODE_SIZE (lra_reg_info[reg->regno].biggest_mode)))
739 lra_reg_info[reg->regno].biggest_mode = reg->biggest_mode;
740 else if (reg->regno < FIRST_PSEUDO_REGISTER)
741 lra_hard_reg_usage[reg->regno] += freq;
743 call_p = CALL_P (curr_insn);
744 if (complete_info_p
745 && set != NULL_RTX
746 && REG_P (SET_DEST (set)) && REG_P (SET_SRC (set))
747 /* Check that source regno does not conflict with
748 destination regno to exclude most impossible
749 preferences. */
750 && ((((src_regno = REGNO (SET_SRC (set))) >= FIRST_PSEUDO_REGISTER
751 && ! sparseset_bit_p (pseudos_live, src_regno))
752 || (src_regno < FIRST_PSEUDO_REGISTER
753 && ! TEST_HARD_REG_BIT (hard_regs_live, src_regno)))
754 /* It might be 'inheritance pseudo <- reload pseudo'. */
755 || (src_regno >= lra_constraint_new_regno_start
756 && ((int) REGNO (SET_DEST (set))
757 >= lra_constraint_new_regno_start)
758 /* Remember to skip special cases where src/dest regnos are
759 the same, e.g. insn SET pattern has matching constraints
760 like =r,0. */
761 && src_regno != (int) REGNO (SET_DEST (set)))))
763 int hard_regno = -1, regno = -1;
765 dst_regno = REGNO (SET_DEST (set));
766 if (dst_regno >= lra_constraint_new_regno_start
767 && src_regno >= lra_constraint_new_regno_start)
769 /* It might be still an original (non-reload) insn with
770 one unused output and a constraint requiring to use
771 the same reg for input/output operands. In this case
772 dst_regno and src_regno have the same value, we don't
773 need a misleading copy for this case. */
774 if (dst_regno != src_regno)
775 lra_create_copy (dst_regno, src_regno, freq);
777 else if (dst_regno >= lra_constraint_new_regno_start)
779 if ((hard_regno = src_regno) >= FIRST_PSEUDO_REGISTER)
780 hard_regno = reg_renumber[src_regno];
781 regno = dst_regno;
783 else if (src_regno >= lra_constraint_new_regno_start)
785 if ((hard_regno = dst_regno) >= FIRST_PSEUDO_REGISTER)
786 hard_regno = reg_renumber[dst_regno];
787 regno = src_regno;
789 if (regno >= 0 && hard_regno >= 0)
790 lra_setup_reload_pseudo_preferenced_hard_reg
791 (regno, hard_regno, freq);
794 sparseset_clear (start_living);
796 /* Try to avoid unnecessary program point increments, this saves
797 a lot of time in remove_some_program_points_and_update_live_ranges.
798 We only need an increment if something becomes live or dies at this
799 program point. */
800 need_curr_point_incr = false;
802 /* Mark each defined value as live. We need to do this for
803 unused values because they still conflict with quantities
804 that are live at the time of the definition. */
805 for (reg = curr_id->regs; reg != NULL; reg = reg->next)
806 if (reg->type != OP_IN)
808 need_curr_point_incr
809 |= mark_regno_live (reg->regno, reg->biggest_mode,
810 curr_point);
811 check_pseudos_live_through_calls (reg->regno);
814 for (reg = curr_static_id->hard_regs; reg != NULL; reg = reg->next)
815 if (reg->type != OP_IN)
816 make_hard_regno_born (reg->regno, false);
818 if (curr_id->arg_hard_regs != NULL)
819 for (i = 0; (regno = curr_id->arg_hard_regs[i]) >= 0; i++)
820 if (regno >= FIRST_PSEUDO_REGISTER)
821 /* It is a clobber. */
822 make_hard_regno_born (regno - FIRST_PSEUDO_REGISTER, false);
824 sparseset_copy (unused_set, start_living);
826 sparseset_clear (start_dying);
828 /* See which defined values die here. */
829 for (reg = curr_id->regs; reg != NULL; reg = reg->next)
830 if (reg->type == OP_OUT && ! reg->early_clobber && ! reg->subreg_p)
831 need_curr_point_incr
832 |= mark_regno_dead (reg->regno, reg->biggest_mode,
833 curr_point);
835 for (reg = curr_static_id->hard_regs; reg != NULL; reg = reg->next)
836 if (reg->type == OP_OUT && ! reg->early_clobber && ! reg->subreg_p)
837 make_hard_regno_dead (reg->regno);
839 if (curr_id->arg_hard_regs != NULL)
840 for (i = 0; (regno = curr_id->arg_hard_regs[i]) >= 0; i++)
841 if (regno >= FIRST_PSEUDO_REGISTER)
842 /* It is a clobber. */
843 make_hard_regno_dead (regno - FIRST_PSEUDO_REGISTER);
845 if (call_p)
847 if (flag_ipa_ra)
849 HARD_REG_SET this_call_used_reg_set;
850 get_call_reg_set_usage (curr_insn, &this_call_used_reg_set,
851 call_used_reg_set);
853 EXECUTE_IF_SET_IN_SPARSESET (pseudos_live, j)
854 IOR_HARD_REG_SET (lra_reg_info[j].actual_call_used_reg_set,
855 this_call_used_reg_set);
858 sparseset_ior (pseudos_live_through_calls,
859 pseudos_live_through_calls, pseudos_live);
860 if (cfun->has_nonlocal_label
861 || find_reg_note (curr_insn, REG_SETJMP,
862 NULL_RTX) != NULL_RTX)
863 sparseset_ior (pseudos_live_through_setjumps,
864 pseudos_live_through_setjumps, pseudos_live);
867 /* Increment the current program point if we must. */
868 if (need_curr_point_incr)
869 next_program_point (curr_point, freq);
871 sparseset_clear (start_living);
873 need_curr_point_incr = false;
875 /* Mark each used value as live. */
876 for (reg = curr_id->regs; reg != NULL; reg = reg->next)
877 if (reg->type == OP_IN)
879 need_curr_point_incr
880 |= mark_regno_live (reg->regno, reg->biggest_mode,
881 curr_point);
882 check_pseudos_live_through_calls (reg->regno);
885 for (reg = curr_static_id->hard_regs; reg != NULL; reg = reg->next)
886 if (reg->type == OP_IN)
887 make_hard_regno_born (reg->regno, false);
889 if (curr_id->arg_hard_regs != NULL)
890 /* Make argument hard registers live. Don't create conflict
891 of used REAL_PIC_OFFSET_TABLE_REGNUM and the pic pseudo. */
892 for (i = 0; (regno = curr_id->arg_hard_regs[i]) >= 0; i++)
893 if (regno < FIRST_PSEUDO_REGISTER)
894 make_hard_regno_born (regno, true);
896 sparseset_and_compl (dead_set, start_living, start_dying);
898 /* Mark early clobber outputs dead. */
899 for (reg = curr_id->regs; reg != NULL; reg = reg->next)
900 if (reg->type == OP_OUT && reg->early_clobber && ! reg->subreg_p)
901 need_curr_point_incr
902 |= mark_regno_dead (reg->regno, reg->biggest_mode,
903 curr_point);
905 for (reg = curr_static_id->hard_regs; reg != NULL; reg = reg->next)
906 if (reg->type == OP_OUT && reg->early_clobber && ! reg->subreg_p)
907 make_hard_regno_dead (reg->regno);
909 if (need_curr_point_incr)
910 next_program_point (curr_point, freq);
912 /* Update notes. */
913 for (link_loc = &REG_NOTES (curr_insn); (link = *link_loc) != NULL_RTX;)
915 if (REG_NOTE_KIND (link) != REG_DEAD
916 && REG_NOTE_KIND (link) != REG_UNUSED)
918 else if (REG_P (XEXP (link, 0)))
920 regno = REGNO (XEXP (link, 0));
921 if ((REG_NOTE_KIND (link) == REG_DEAD
922 && ! sparseset_bit_p (dead_set, regno))
923 || (REG_NOTE_KIND (link) == REG_UNUSED
924 && ! sparseset_bit_p (unused_set, regno)))
926 *link_loc = XEXP (link, 1);
927 continue;
929 if (REG_NOTE_KIND (link) == REG_DEAD)
930 sparseset_clear_bit (dead_set, regno);
931 else if (REG_NOTE_KIND (link) == REG_UNUSED)
932 sparseset_clear_bit (unused_set, regno);
934 link_loc = &XEXP (link, 1);
936 EXECUTE_IF_SET_IN_SPARSESET (dead_set, j)
937 add_reg_note (curr_insn, REG_DEAD, regno_reg_rtx[j]);
938 EXECUTE_IF_SET_IN_SPARSESET (unused_set, j)
939 add_reg_note (curr_insn, REG_UNUSED, regno_reg_rtx[j]);
942 if (bb_has_eh_pred (bb))
943 for (j = 0; ; ++j)
945 unsigned int regno = EH_RETURN_DATA_REGNO (j);
947 if (regno == INVALID_REGNUM)
948 break;
949 make_hard_regno_born (regno, false);
952 /* Pseudos can't go in stack regs at the start of a basic block that
953 is reached by an abnormal edge. Likewise for call clobbered regs,
954 because caller-save, fixup_abnormal_edges and possibly the table
955 driven EH machinery are not quite ready to handle such pseudos
956 live across such edges. */
957 if (bb_has_abnormal_pred (bb))
959 #ifdef STACK_REGS
960 EXECUTE_IF_SET_IN_SPARSESET (pseudos_live, px)
961 lra_reg_info[px].no_stack_p = true;
962 for (px = FIRST_STACK_REG; px <= LAST_STACK_REG; px++)
963 make_hard_regno_born (px, false);
964 #endif
965 /* No need to record conflicts for call clobbered regs if we
966 have nonlocal labels around, as we don't ever try to
967 allocate such regs in this case. */
968 if (!cfun->has_nonlocal_label && bb_has_abnormal_call_pred (bb))
969 for (px = 0; px < FIRST_PSEUDO_REGISTER; px++)
970 if (call_used_regs[px]
971 #ifdef REAL_PIC_OFFSET_TABLE_REGNUM
972 /* We should create a conflict of PIC pseudo with PIC
973 hard reg as PIC hard reg can have a wrong value after
974 jump described by the abnormal edge. In this case we
975 can not allocate PIC hard reg to PIC pseudo as PIC
976 pseudo will also have a wrong value. */
977 || (px == REAL_PIC_OFFSET_TABLE_REGNUM
978 && pic_offset_table_rtx != NULL_RTX
979 && REGNO (pic_offset_table_rtx) >= FIRST_PSEUDO_REGISTER)
980 #endif
982 make_hard_regno_born (px, false);
985 bool live_change_p = false;
986 /* Check if bb border live info was changed. */
987 unsigned int live_pseudos_num = 0;
988 EXECUTE_IF_SET_IN_BITMAP (df_get_live_in (bb),
989 FIRST_PSEUDO_REGISTER, j, bi)
991 live_pseudos_num++;
992 if (! sparseset_bit_p (pseudos_live, j))
994 live_change_p = true;
995 if (lra_dump_file != NULL)
996 fprintf (lra_dump_file,
997 " r%d is removed as live at bb%d start\n", j, bb->index);
998 break;
1001 if (! live_change_p
1002 && sparseset_cardinality (pseudos_live) != live_pseudos_num)
1004 live_change_p = true;
1005 if (lra_dump_file != NULL)
1006 EXECUTE_IF_SET_IN_SPARSESET (pseudos_live, j)
1007 if (! bitmap_bit_p (df_get_live_in (bb), j))
1008 fprintf (lra_dump_file,
1009 " r%d is added to live at bb%d start\n", j, bb->index);
1011 /* See if we'll need an increment at the end of this basic block.
1012 An increment is needed if the PSEUDOS_LIVE set is not empty,
1013 to make sure the finish points are set up correctly. */
1014 need_curr_point_incr = (sparseset_cardinality (pseudos_live) > 0);
1016 EXECUTE_IF_SET_IN_SPARSESET (pseudos_live, i)
1017 mark_pseudo_dead (i, curr_point);
1019 EXECUTE_IF_SET_IN_BITMAP (df_get_live_in (bb), FIRST_PSEUDO_REGISTER, j, bi)
1021 if (sparseset_cardinality (pseudos_live_through_calls) == 0)
1022 break;
1023 if (sparseset_bit_p (pseudos_live_through_calls, j))
1024 check_pseudos_live_through_calls (j);
1027 if (need_curr_point_incr)
1028 next_program_point (curr_point, freq);
1030 return live_change_p;
1033 /* Compress pseudo live ranges by removing program points where
1034 nothing happens. Complexity of many algorithms in LRA is linear
1035 function of program points number. To speed up the code we try to
1036 minimize the number of the program points here. */
1037 static void
1038 remove_some_program_points_and_update_live_ranges (void)
1040 unsigned i;
1041 int n, max_regno;
1042 int *map;
1043 lra_live_range_t r, prev_r, next_r;
1044 sbitmap born_or_dead, born, dead;
1045 sbitmap_iterator sbi;
1046 bool born_p, dead_p, prev_born_p, prev_dead_p;
1048 born = sbitmap_alloc (lra_live_max_point);
1049 dead = sbitmap_alloc (lra_live_max_point);
1050 bitmap_clear (born);
1051 bitmap_clear (dead);
1052 max_regno = max_reg_num ();
1053 for (i = FIRST_PSEUDO_REGISTER; i < (unsigned) max_regno; i++)
1055 for (r = lra_reg_info[i].live_ranges; r != NULL; r = r->next)
1057 lra_assert (r->start <= r->finish);
1058 bitmap_set_bit (born, r->start);
1059 bitmap_set_bit (dead, r->finish);
1062 born_or_dead = sbitmap_alloc (lra_live_max_point);
1063 bitmap_ior (born_or_dead, born, dead);
1064 map = XCNEWVEC (int, lra_live_max_point);
1065 n = -1;
1066 prev_born_p = prev_dead_p = false;
1067 EXECUTE_IF_SET_IN_BITMAP (born_or_dead, 0, i, sbi)
1069 born_p = bitmap_bit_p (born, i);
1070 dead_p = bitmap_bit_p (dead, i);
1071 if ((prev_born_p && ! prev_dead_p && born_p && ! dead_p)
1072 || (prev_dead_p && ! prev_born_p && dead_p && ! born_p))
1074 map[i] = n;
1075 lra_point_freq[n] = MAX (lra_point_freq[n], lra_point_freq[i]);
1077 else
1079 map[i] = ++n;
1080 lra_point_freq[n] = lra_point_freq[i];
1082 prev_born_p = born_p;
1083 prev_dead_p = dead_p;
1085 sbitmap_free (born_or_dead);
1086 sbitmap_free (born);
1087 sbitmap_free (dead);
1088 n++;
1089 if (lra_dump_file != NULL)
1090 fprintf (lra_dump_file, "Compressing live ranges: from %d to %d - %d%%\n",
1091 lra_live_max_point, n, 100 * n / lra_live_max_point);
1092 if (n < lra_live_max_point)
1094 lra_live_max_point = n;
1095 for (i = FIRST_PSEUDO_REGISTER; i < (unsigned) max_regno; i++)
1097 for (prev_r = NULL, r = lra_reg_info[i].live_ranges;
1098 r != NULL;
1099 r = next_r)
1101 next_r = r->next;
1102 r->start = map[r->start];
1103 r->finish = map[r->finish];
1104 if (prev_r == NULL || prev_r->start > r->finish + 1)
1106 prev_r = r;
1107 continue;
1109 prev_r->start = r->start;
1110 prev_r->next = next_r;
1111 delete r;
1115 free (map);
1118 /* Print live ranges R to file F. */
1119 void
1120 lra_print_live_range_list (FILE *f, lra_live_range_t r)
1122 for (; r != NULL; r = r->next)
1123 fprintf (f, " [%d..%d]", r->start, r->finish);
1124 fprintf (f, "\n");
1127 DEBUG_FUNCTION void
1128 debug (lra_live_range &ref)
1130 lra_print_live_range_list (stderr, &ref);
1133 DEBUG_FUNCTION void
1134 debug (lra_live_range *ptr)
1136 if (ptr)
1137 debug (*ptr);
1138 else
1139 fprintf (stderr, "<nil>\n");
1142 /* Print live ranges R to stderr. */
1143 void
1144 lra_debug_live_range_list (lra_live_range_t r)
1146 lra_print_live_range_list (stderr, r);
1149 /* Print live ranges of pseudo REGNO to file F. */
1150 static void
1151 print_pseudo_live_ranges (FILE *f, int regno)
1153 if (lra_reg_info[regno].live_ranges == NULL)
1154 return;
1155 fprintf (f, " r%d:", regno);
1156 lra_print_live_range_list (f, lra_reg_info[regno].live_ranges);
1159 /* Print live ranges of pseudo REGNO to stderr. */
1160 void
1161 lra_debug_pseudo_live_ranges (int regno)
1163 print_pseudo_live_ranges (stderr, regno);
1166 /* Print live ranges of all pseudos to file F. */
1167 static void
1168 print_live_ranges (FILE *f)
1170 int i, max_regno;
1172 max_regno = max_reg_num ();
1173 for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
1174 print_pseudo_live_ranges (f, i);
1177 /* Print live ranges of all pseudos to stderr. */
1178 void
1179 lra_debug_live_ranges (void)
1181 print_live_ranges (stderr);
1184 /* Compress pseudo live ranges. */
1185 static void
1186 compress_live_ranges (void)
1188 remove_some_program_points_and_update_live_ranges ();
1189 if (lra_dump_file != NULL)
1191 fprintf (lra_dump_file, "Ranges after the compression:\n");
1192 print_live_ranges (lra_dump_file);
1198 /* The number of the current live range pass. */
1199 int lra_live_range_iter;
1201 /* The function creates live ranges only for memory pseudos (or for
1202 all ones if ALL_P), set up CONFLICT_HARD_REGS for the pseudos. It
1203 also does dead insn elimination if DEAD_INSN_P and global live
1204 analysis only for pseudos and only if the pseudo live info was
1205 changed on a BB border. Return TRUE if the live info was
1206 changed. */
1207 static bool
1208 lra_create_live_ranges_1 (bool all_p, bool dead_insn_p)
1210 basic_block bb;
1211 int i, hard_regno, max_regno = max_reg_num ();
1212 int curr_point;
1213 bool bb_live_change_p, have_referenced_pseudos = false;
1215 timevar_push (TV_LRA_CREATE_LIVE_RANGES);
1217 complete_info_p = all_p;
1218 if (lra_dump_file != NULL)
1219 fprintf (lra_dump_file,
1220 "\n********** Pseudo live ranges #%d: **********\n\n",
1221 ++lra_live_range_iter);
1222 memset (lra_hard_reg_usage, 0, sizeof (lra_hard_reg_usage));
1223 for (i = 0; i < max_regno; i++)
1225 lra_reg_info[i].live_ranges = NULL;
1226 CLEAR_HARD_REG_SET (lra_reg_info[i].conflict_hard_regs);
1227 lra_reg_info[i].preferred_hard_regno1 = -1;
1228 lra_reg_info[i].preferred_hard_regno2 = -1;
1229 lra_reg_info[i].preferred_hard_regno_profit1 = 0;
1230 lra_reg_info[i].preferred_hard_regno_profit2 = 0;
1231 #ifdef STACK_REGS
1232 lra_reg_info[i].no_stack_p = false;
1233 #endif
1234 /* The biggest mode is already set but its value might be to
1235 conservative because of recent transformation. Here in this
1236 file we recalculate it again as it costs practically
1237 nothing. */
1238 if (regno_reg_rtx[i] != NULL_RTX)
1239 lra_reg_info[i].biggest_mode = GET_MODE (regno_reg_rtx[i]);
1240 else
1241 lra_reg_info[i].biggest_mode = VOIDmode;
1242 #ifdef ENABLE_CHECKING
1243 lra_reg_info[i].call_p = false;
1244 #endif
1245 if (i >= FIRST_PSEUDO_REGISTER
1246 && lra_reg_info[i].nrefs != 0)
1248 if ((hard_regno = reg_renumber[i]) >= 0)
1249 lra_hard_reg_usage[hard_regno] += lra_reg_info[i].freq;
1250 have_referenced_pseudos = true;
1253 lra_free_copies ();
1255 /* Under some circumstances, we can have functions without pseudo
1256 registers. For such functions, lra_live_max_point will be 0,
1257 see e.g. PR55604, and there's nothing more to do for us here. */
1258 if (! have_referenced_pseudos)
1260 timevar_pop (TV_LRA_CREATE_LIVE_RANGES);
1261 return false;
1264 pseudos_live = sparseset_alloc (max_regno);
1265 pseudos_live_through_calls = sparseset_alloc (max_regno);
1266 pseudos_live_through_setjumps = sparseset_alloc (max_regno);
1267 start_living = sparseset_alloc (max_regno);
1268 start_dying = sparseset_alloc (max_regno);
1269 dead_set = sparseset_alloc (max_regno);
1270 unused_set = sparseset_alloc (max_regno);
1271 curr_point = 0;
1272 point_freq_vec.create (get_max_uid () * 2);
1273 lra_point_freq = point_freq_vec.address ();
1274 int *post_order_rev_cfg = XNEWVEC (int, last_basic_block_for_fn (cfun));
1275 int n_blocks_inverted = inverted_post_order_compute (post_order_rev_cfg);
1276 lra_assert (n_blocks_inverted == n_basic_blocks_for_fn (cfun));
1277 bb_live_change_p = false;
1278 for (i = n_blocks_inverted - 1; i >= 0; --i)
1280 bb = BASIC_BLOCK_FOR_FN (cfun, post_order_rev_cfg[i]);
1281 if (bb == EXIT_BLOCK_PTR_FOR_FN (cfun) || bb
1282 == ENTRY_BLOCK_PTR_FOR_FN (cfun))
1283 continue;
1284 if (process_bb_lives (bb, curr_point, dead_insn_p))
1285 bb_live_change_p = true;
1287 if (bb_live_change_p)
1289 /* We need to clear pseudo live info as some pseudos can
1290 disappear, e.g. pseudos with used equivalences. */
1291 FOR_EACH_BB_FN (bb, cfun)
1293 bitmap_clear_range (df_get_live_in (bb), FIRST_PSEUDO_REGISTER,
1294 max_regno - FIRST_PSEUDO_REGISTER);
1295 bitmap_clear_range (df_get_live_out (bb), FIRST_PSEUDO_REGISTER,
1296 max_regno - FIRST_PSEUDO_REGISTER);
1298 /* As we did not change CFG since LRA start we can use
1299 DF-infrastructure solver to solve live data flow problem. */
1300 df_simple_dataflow
1301 (DF_BACKWARD, NULL, live_con_fun_0, live_con_fun_n,
1302 live_trans_fun, &all_blocks,
1303 df_get_postorder (DF_BACKWARD), df_get_n_blocks (DF_BACKWARD));
1304 if (lra_dump_file != NULL)
1306 fprintf (lra_dump_file,
1307 "Global pseudo live data have been updated:\n");
1308 basic_block bb;
1309 FOR_EACH_BB_FN (bb, cfun)
1311 bb_data_t bb_info = get_bb_data (bb);
1312 bitmap bb_livein = df_get_live_in (bb);
1313 bitmap bb_liveout = df_get_live_out (bb);
1315 fprintf (lra_dump_file, "\nBB %d:\n", bb->index);
1316 lra_dump_bitmap_with_title (" gen:",
1317 &bb_info->gen_pseudos, bb->index);
1318 lra_dump_bitmap_with_title (" killed:",
1319 &bb_info->killed_pseudos, bb->index);
1320 lra_dump_bitmap_with_title (" livein:", bb_livein, bb->index);
1321 lra_dump_bitmap_with_title (" liveout:", bb_liveout, bb->index);
1325 free (post_order_rev_cfg);
1326 lra_live_max_point = curr_point;
1327 if (lra_dump_file != NULL)
1328 print_live_ranges (lra_dump_file);
1329 /* Clean up. */
1330 sparseset_free (unused_set);
1331 sparseset_free (dead_set);
1332 sparseset_free (start_dying);
1333 sparseset_free (start_living);
1334 sparseset_free (pseudos_live_through_calls);
1335 sparseset_free (pseudos_live_through_setjumps);
1336 sparseset_free (pseudos_live);
1337 compress_live_ranges ();
1338 timevar_pop (TV_LRA_CREATE_LIVE_RANGES);
1339 return bb_live_change_p;
1342 /* The main entry function creates live-ranges and other live info
1343 necessary for the assignment sub-pass. It uses
1344 lra_creates_live_ranges_1 -- so read comments for the
1345 function. */
1346 void
1347 lra_create_live_ranges (bool all_p, bool dead_insn_p)
1349 if (! lra_create_live_ranges_1 (all_p, dead_insn_p))
1350 return;
1351 if (lra_dump_file != NULL)
1352 fprintf (lra_dump_file, "Live info was changed -- recalculate it\n");
1353 /* Live info was changed on a bb border. It means that some info,
1354 e.g. about conflict regs, calls crossed, and live ranges may be
1355 wrong. We need this info for allocation. So recalculate it
1356 again but without removing dead insns which can change live info
1357 again. Repetitive live range calculations are expensive therefore
1358 we stop here as we already have correct info although some
1359 improvement in rare cases could be possible on this sub-pass if
1360 we do dead insn elimination again (still the improvement may
1361 happen later). */
1362 lra_clear_live_ranges ();
1363 bool res = lra_create_live_ranges_1 (all_p, false);
1364 lra_assert (! res);
1367 /* Finish all live ranges. */
1368 void
1369 lra_clear_live_ranges (void)
1371 int i;
1373 for (i = 0; i < max_reg_num (); i++)
1374 free_live_range_list (lra_reg_info[i].live_ranges);
1375 point_freq_vec.release ();
1378 /* Initialize live ranges data once per function. */
1379 void
1380 lra_live_ranges_init (void)
1382 bitmap_initialize (&temp_bitmap, &reg_obstack);
1383 initiate_live_solver ();
1386 /* Finish live ranges data once per function. */
1387 void
1388 lra_live_ranges_finish (void)
1390 finish_live_solver ();
1391 bitmap_clear (&temp_bitmap);
1392 lra_live_range::pool.release ();