[ARM] Fix assembly comment syntax in -mprint-tune-info
[official-gcc.git] / gcc / lra-lives.c
blobf0194387c6319f60617285d96bba2eeeaaf56810
1 /* Build live ranges for pseudos.
2 Copyright (C) 2010-2017 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 "rtl.h"
33 #include "tree.h"
34 #include "predict.h"
35 #include "df.h"
36 #include "memmodel.h"
37 #include "tm_p.h"
38 #include "insn-config.h"
39 #include "regs.h"
40 #include "ira.h"
41 #include "recog.h"
42 #include "cfganal.h"
43 #include "sparseset.h"
44 #include "lra-int.h"
46 /* Program points are enumerated by numbers from range
47 0..LRA_LIVE_MAX_POINT-1. There are approximately two times more
48 program points than insns. Program points are places in the
49 program where liveness info can be changed. In most general case
50 (there are more complicated cases too) some program points
51 correspond to places where input operand dies and other ones
52 correspond to places where output operands are born. */
53 int lra_live_max_point;
55 /* Accumulated execution frequency of all references for each hard
56 register. */
57 int lra_hard_reg_usage[FIRST_PSEUDO_REGISTER];
59 /* A global flag whose true value says to build live ranges for all
60 pseudos, otherwise the live ranges only for pseudos got memory is
61 build. True value means also building copies and setting up hard
62 register preferences. The complete info is necessary only for the
63 assignment pass. The complete info is not needed for the
64 coalescing and spill passes. */
65 static bool complete_info_p;
67 /* Pseudos live at current point in the RTL scan. */
68 static sparseset pseudos_live;
70 /* Pseudos probably living through calls and setjumps. As setjump is
71 a call too, if a bit in PSEUDOS_LIVE_THROUGH_SETJUMPS is set up
72 then the corresponding bit in PSEUDOS_LIVE_THROUGH_CALLS is set up
73 too. These data are necessary for cases when only one subreg of a
74 multi-reg pseudo is set up after a call. So we decide it is
75 probably live when traversing bb backward. We are sure about
76 living when we see its usage or definition of the pseudo. */
77 static sparseset pseudos_live_through_calls;
78 static sparseset pseudos_live_through_setjumps;
80 /* Set of hard regs (except eliminable ones) currently live. */
81 static HARD_REG_SET hard_regs_live;
83 /* Set of pseudos and hard registers start living/dying in the current
84 insn. These sets are used to update REG_DEAD and REG_UNUSED notes
85 in the insn. */
86 static sparseset start_living, start_dying;
88 /* Set of pseudos and hard regs dead and unused in the current
89 insn. */
90 static sparseset unused_set, dead_set;
92 /* Bitmap used for holding intermediate bitmap operation results. */
93 static bitmap_head temp_bitmap;
95 /* Pool for pseudo live ranges. */
96 static object_allocator<lra_live_range> lra_live_range_pool ("live ranges");
98 /* Free live range list LR. */
99 static void
100 free_live_range_list (lra_live_range_t lr)
102 lra_live_range_t next;
104 while (lr != NULL)
106 next = lr->next;
107 lra_live_range_pool.remove (lr);
108 lr = next;
112 /* Create and return pseudo live range with given attributes. */
113 static lra_live_range_t
114 create_live_range (int regno, int start, int finish, lra_live_range_t next)
116 lra_live_range_t p = lra_live_range_pool.allocate ();
117 p->regno = regno;
118 p->start = start;
119 p->finish = finish;
120 p->next = next;
121 return p;
124 /* Copy live range R and return the result. */
125 static lra_live_range_t
126 copy_live_range (lra_live_range_t r)
128 return new (lra_live_range_pool) lra_live_range (*r);
131 /* Copy live range list given by its head R and return the result. */
132 lra_live_range_t
133 lra_copy_live_range_list (lra_live_range_t r)
135 lra_live_range_t p, first, *chain;
137 first = NULL;
138 for (chain = &first; r != NULL; r = r->next)
140 p = copy_live_range (r);
141 *chain = p;
142 chain = &p->next;
144 return first;
147 /* Merge *non-intersected* ranges R1 and R2 and returns the result.
148 The function maintains the order of ranges and tries to minimize
149 size of the result range list. Ranges R1 and R2 may not be used
150 after the call. */
151 lra_live_range_t
152 lra_merge_live_ranges (lra_live_range_t r1, lra_live_range_t r2)
154 lra_live_range_t first, last;
156 if (r1 == NULL)
157 return r2;
158 if (r2 == NULL)
159 return r1;
160 for (first = last = NULL; r1 != NULL && r2 != NULL;)
162 if (r1->start < r2->start)
163 std::swap (r1, r2);
165 if (r1->start == r2->finish + 1)
167 /* Joint ranges: merge r1 and r2 into r1. */
168 r1->start = r2->start;
169 lra_live_range_t temp = r2;
170 r2 = r2->next;
171 lra_live_range_pool.remove (temp);
173 else
175 gcc_assert (r2->finish + 1 < r1->start);
176 /* Add r1 to the result. */
177 if (first == NULL)
178 first = last = r1;
179 else
181 last->next = r1;
182 last = r1;
184 r1 = r1->next;
187 if (r1 != NULL)
189 if (first == NULL)
190 first = r1;
191 else
192 last->next = r1;
194 else
196 lra_assert (r2 != NULL);
197 if (first == NULL)
198 first = r2;
199 else
200 last->next = r2;
202 return first;
205 /* Return TRUE if live ranges R1 and R2 intersect. */
206 bool
207 lra_intersected_live_ranges_p (lra_live_range_t r1, lra_live_range_t r2)
209 /* Remember the live ranges are always kept ordered. */
210 while (r1 != NULL && r2 != NULL)
212 if (r1->start > r2->finish)
213 r1 = r1->next;
214 else if (r2->start > r1->finish)
215 r2 = r2->next;
216 else
217 return true;
219 return false;
222 /* The function processing birth of hard register REGNO. It updates
223 living hard regs, START_LIVING, and conflict hard regs for living
224 pseudos. Conflict hard regs for the pic pseudo is not updated if
225 REGNO is REAL_PIC_OFFSET_TABLE_REGNUM and CHECK_PIC_PSEUDO_P is
226 true. */
227 static void
228 make_hard_regno_born (int regno, bool check_pic_pseudo_p ATTRIBUTE_UNUSED)
230 unsigned int i;
232 lra_assert (regno < FIRST_PSEUDO_REGISTER);
233 if (TEST_HARD_REG_BIT (hard_regs_live, regno))
234 return;
235 SET_HARD_REG_BIT (hard_regs_live, regno);
236 sparseset_set_bit (start_living, regno);
237 EXECUTE_IF_SET_IN_SPARSESET (pseudos_live, i)
238 #ifdef REAL_PIC_OFFSET_TABLE_REGNUM
239 if (! check_pic_pseudo_p
240 || regno != REAL_PIC_OFFSET_TABLE_REGNUM
241 || pic_offset_table_rtx == NULL
242 || i != REGNO (pic_offset_table_rtx))
243 #endif
244 SET_HARD_REG_BIT (lra_reg_info[i].conflict_hard_regs, regno);
247 /* Process the death of hard register REGNO. This updates
248 hard_regs_live and START_DYING. */
249 static void
250 make_hard_regno_dead (int regno)
252 lra_assert (regno < FIRST_PSEUDO_REGISTER);
253 if (! TEST_HARD_REG_BIT (hard_regs_live, regno))
254 return;
255 sparseset_set_bit (start_dying, regno);
256 CLEAR_HARD_REG_BIT (hard_regs_live, regno);
259 /* Mark pseudo REGNO as living at program point POINT, update conflicting
260 hard registers of the pseudo and START_LIVING, and start a new live
261 range for the pseudo corresponding to REGNO if it is necessary. */
262 static void
263 mark_pseudo_live (int regno, int point)
265 lra_live_range_t p;
267 lra_assert (regno >= FIRST_PSEUDO_REGISTER);
268 lra_assert (! sparseset_bit_p (pseudos_live, regno));
269 sparseset_set_bit (pseudos_live, regno);
270 IOR_HARD_REG_SET (lra_reg_info[regno].conflict_hard_regs, hard_regs_live);
272 if ((complete_info_p || lra_get_regno_hard_regno (regno) < 0)
273 && ((p = lra_reg_info[regno].live_ranges) == NULL
274 || (p->finish != point && p->finish + 1 != point)))
275 lra_reg_info[regno].live_ranges
276 = create_live_range (regno, point, -1, p);
277 sparseset_set_bit (start_living, regno);
280 /* Mark pseudo REGNO as not living at program point POINT and update
281 START_DYING.
282 This finishes the current live range for the pseudo corresponding
283 to REGNO. */
284 static void
285 mark_pseudo_dead (int regno, int point)
287 lra_live_range_t p;
289 lra_assert (regno >= FIRST_PSEUDO_REGISTER);
290 lra_assert (sparseset_bit_p (pseudos_live, regno));
291 sparseset_clear_bit (pseudos_live, regno);
292 sparseset_set_bit (start_dying, regno);
293 if (complete_info_p || lra_get_regno_hard_regno (regno) < 0)
295 p = lra_reg_info[regno].live_ranges;
296 lra_assert (p != NULL);
297 p->finish = point;
301 /* The corresponding bitmaps of BB currently being processed. */
302 static bitmap bb_killed_pseudos, bb_gen_pseudos;
304 /* Mark register REGNO (pseudo or hard register) in MODE as live at
305 program point POINT. Update BB_GEN_PSEUDOS.
306 Return TRUE if the liveness tracking sets were modified, or FALSE
307 if nothing changed. */
308 static bool
309 mark_regno_live (int regno, machine_mode mode, int point)
311 int last;
312 bool changed = false;
314 if (regno < FIRST_PSEUDO_REGISTER)
316 for (last = regno + hard_regno_nregs[regno][mode];
317 regno < last;
318 regno++)
319 make_hard_regno_born (regno, false);
321 else
323 if (! sparseset_bit_p (pseudos_live, regno))
325 mark_pseudo_live (regno, point);
326 changed = true;
328 bitmap_set_bit (bb_gen_pseudos, regno);
330 return changed;
334 /* Mark register REGNO in MODE as dead at program point POINT. Update
335 BB_GEN_PSEUDOS and BB_KILLED_PSEUDOS. Return TRUE if the liveness
336 tracking sets were modified, or FALSE if nothing changed. */
337 static bool
338 mark_regno_dead (int regno, machine_mode mode, int point)
340 int last;
341 bool changed = false;
343 if (regno < FIRST_PSEUDO_REGISTER)
345 for (last = regno + hard_regno_nregs[regno][mode];
346 regno < last;
347 regno++)
348 make_hard_regno_dead (regno);
350 else
352 if (sparseset_bit_p (pseudos_live, regno))
354 mark_pseudo_dead (regno, point);
355 changed = true;
357 bitmap_clear_bit (bb_gen_pseudos, regno);
358 bitmap_set_bit (bb_killed_pseudos, regno);
360 return changed;
365 /* This page contains code for making global live analysis of pseudos.
366 The code works only when pseudo live info is changed on a BB
367 border. That might be a consequence of some global transformations
368 in LRA, e.g. PIC pseudo reuse or rematerialization. */
370 /* Structure describing local BB data used for pseudo
371 live-analysis. */
372 struct bb_data_pseudos
374 /* Basic block about which the below data are. */
375 basic_block bb;
376 bitmap_head killed_pseudos; /* pseudos killed in the BB. */
377 bitmap_head gen_pseudos; /* pseudos generated in the BB. */
380 /* Array for all BB data. Indexed by the corresponding BB index. */
381 typedef struct bb_data_pseudos *bb_data_t;
383 /* All basic block data are referred through the following array. */
384 static bb_data_t bb_data;
386 /* Two small functions for access to the bb data. */
387 static inline bb_data_t
388 get_bb_data (basic_block bb)
390 return &bb_data[(bb)->index];
393 static inline bb_data_t
394 get_bb_data_by_index (int index)
396 return &bb_data[index];
399 /* Bitmap with all hard regs. */
400 static bitmap_head all_hard_regs_bitmap;
402 /* The transfer function used by the DF equation solver to propagate
403 live info through block with BB_INDEX according to the following
404 equation:
406 bb.livein = (bb.liveout - bb.kill) OR bb.gen
408 static bool
409 live_trans_fun (int bb_index)
411 basic_block bb = get_bb_data_by_index (bb_index)->bb;
412 bitmap bb_liveout = df_get_live_out (bb);
413 bitmap bb_livein = df_get_live_in (bb);
414 bb_data_t bb_info = get_bb_data (bb);
416 bitmap_and_compl (&temp_bitmap, bb_liveout, &all_hard_regs_bitmap);
417 return bitmap_ior_and_compl (bb_livein, &bb_info->gen_pseudos,
418 &temp_bitmap, &bb_info->killed_pseudos);
421 /* The confluence function used by the DF equation solver to set up
422 live info for a block BB without predecessor. */
423 static void
424 live_con_fun_0 (basic_block bb)
426 bitmap_and_into (df_get_live_out (bb), &all_hard_regs_bitmap);
429 /* The confluence function used by the DF equation solver to propagate
430 live info from successor to predecessor on edge E according to the
431 following equation:
433 bb.liveout = 0 for entry block | OR (livein of successors)
435 static bool
436 live_con_fun_n (edge e)
438 basic_block bb = e->src;
439 basic_block dest = e->dest;
440 bitmap bb_liveout = df_get_live_out (bb);
441 bitmap dest_livein = df_get_live_in (dest);
443 return bitmap_ior_and_compl_into (bb_liveout,
444 dest_livein, &all_hard_regs_bitmap);
447 /* Indexes of all function blocks. */
448 static bitmap_head all_blocks;
450 /* Allocate and initialize data needed for global pseudo live
451 analysis. */
452 static void
453 initiate_live_solver (void)
455 bitmap_initialize (&all_hard_regs_bitmap, &reg_obstack);
456 bitmap_set_range (&all_hard_regs_bitmap, 0, FIRST_PSEUDO_REGISTER);
457 bb_data = XNEWVEC (struct bb_data_pseudos, last_basic_block_for_fn (cfun));
458 bitmap_initialize (&all_blocks, &reg_obstack);
460 basic_block bb;
461 FOR_ALL_BB_FN (bb, cfun)
463 bb_data_t bb_info = get_bb_data (bb);
464 bb_info->bb = bb;
465 bitmap_initialize (&bb_info->killed_pseudos, &reg_obstack);
466 bitmap_initialize (&bb_info->gen_pseudos, &reg_obstack);
467 bitmap_set_bit (&all_blocks, bb->index);
471 /* Free all data needed for global pseudo live analysis. */
472 static void
473 finish_live_solver (void)
475 basic_block bb;
477 bitmap_clear (&all_blocks);
478 FOR_ALL_BB_FN (bb, cfun)
480 bb_data_t bb_info = get_bb_data (bb);
481 bitmap_clear (&bb_info->killed_pseudos);
482 bitmap_clear (&bb_info->gen_pseudos);
484 free (bb_data);
485 bitmap_clear (&all_hard_regs_bitmap);
490 /* Insn currently scanned. */
491 static rtx_insn *curr_insn;
492 /* The insn data. */
493 static lra_insn_recog_data_t curr_id;
494 /* The insn static data. */
495 static struct lra_static_insn_data *curr_static_id;
497 /* Vec containing execution frequencies of program points. */
498 static vec<int> point_freq_vec;
500 /* The start of the above vector elements. */
501 int *lra_point_freq;
503 /* Increment the current program point POINT to the next point which has
504 execution frequency FREQ. */
505 static void
506 next_program_point (int &point, int freq)
508 point_freq_vec.safe_push (freq);
509 lra_point_freq = point_freq_vec.address ();
510 point++;
513 /* Update the preference of HARD_REGNO for pseudo REGNO by PROFIT. */
514 void
515 lra_setup_reload_pseudo_preferenced_hard_reg (int regno,
516 int hard_regno, int profit)
518 lra_assert (regno >= lra_constraint_new_regno_start);
519 if (lra_reg_info[regno].preferred_hard_regno1 == hard_regno)
520 lra_reg_info[regno].preferred_hard_regno_profit1 += profit;
521 else if (lra_reg_info[regno].preferred_hard_regno2 == hard_regno)
522 lra_reg_info[regno].preferred_hard_regno_profit2 += profit;
523 else if (lra_reg_info[regno].preferred_hard_regno1 < 0)
525 lra_reg_info[regno].preferred_hard_regno1 = hard_regno;
526 lra_reg_info[regno].preferred_hard_regno_profit1 = profit;
528 else if (lra_reg_info[regno].preferred_hard_regno2 < 0
529 || profit > lra_reg_info[regno].preferred_hard_regno_profit2)
531 lra_reg_info[regno].preferred_hard_regno2 = hard_regno;
532 lra_reg_info[regno].preferred_hard_regno_profit2 = profit;
534 else
535 return;
536 /* Keep the 1st hard regno as more profitable. */
537 if (lra_reg_info[regno].preferred_hard_regno1 >= 0
538 && lra_reg_info[regno].preferred_hard_regno2 >= 0
539 && (lra_reg_info[regno].preferred_hard_regno_profit2
540 > lra_reg_info[regno].preferred_hard_regno_profit1))
542 std::swap (lra_reg_info[regno].preferred_hard_regno1,
543 lra_reg_info[regno].preferred_hard_regno2);
544 std::swap (lra_reg_info[regno].preferred_hard_regno_profit1,
545 lra_reg_info[regno].preferred_hard_regno_profit2);
547 if (lra_dump_file != NULL)
549 if ((hard_regno = lra_reg_info[regno].preferred_hard_regno1) >= 0)
550 fprintf (lra_dump_file,
551 " Hard reg %d is preferable by r%d with profit %d\n",
552 hard_regno, regno,
553 lra_reg_info[regno].preferred_hard_regno_profit1);
554 if ((hard_regno = lra_reg_info[regno].preferred_hard_regno2) >= 0)
555 fprintf (lra_dump_file,
556 " Hard reg %d is preferable by r%d with profit %d\n",
557 hard_regno, regno,
558 lra_reg_info[regno].preferred_hard_regno_profit2);
562 /* Check that REGNO living through calls and setjumps, set up conflict
563 regs using LAST_CALL_USED_REG_SET, and clear corresponding bits in
564 PSEUDOS_LIVE_THROUGH_CALLS and PSEUDOS_LIVE_THROUGH_SETJUMPS. */
565 static inline void
566 check_pseudos_live_through_calls (int regno,
567 HARD_REG_SET last_call_used_reg_set)
569 int hr;
571 if (! sparseset_bit_p (pseudos_live_through_calls, regno))
572 return;
573 sparseset_clear_bit (pseudos_live_through_calls, regno);
574 IOR_HARD_REG_SET (lra_reg_info[regno].conflict_hard_regs,
575 last_call_used_reg_set);
577 for (hr = 0; hr < FIRST_PSEUDO_REGISTER; hr++)
578 if (HARD_REGNO_CALL_PART_CLOBBERED (hr, PSEUDO_REGNO_MODE (regno)))
579 SET_HARD_REG_BIT (lra_reg_info[regno].conflict_hard_regs, hr);
580 lra_reg_info[regno].call_p = true;
581 if (! sparseset_bit_p (pseudos_live_through_setjumps, regno))
582 return;
583 sparseset_clear_bit (pseudos_live_through_setjumps, regno);
584 /* Don't allocate pseudos that cross setjmps or any call, if this
585 function receives a nonlocal goto. */
586 SET_HARD_REG_SET (lra_reg_info[regno].conflict_hard_regs);
589 /* Process insns of the basic block BB to update pseudo live ranges,
590 pseudo hard register conflicts, and insn notes. We do it on
591 backward scan of BB insns. CURR_POINT is the program point where
592 BB ends. The function updates this counter and returns in
593 CURR_POINT the program point where BB starts. The function also
594 does local live info updates and can delete the dead insns if
595 DEAD_INSN_P. It returns true if pseudo live info was
596 changed at the BB start. */
597 static bool
598 process_bb_lives (basic_block bb, int &curr_point, bool dead_insn_p)
600 int i, regno, freq;
601 unsigned int j;
602 bitmap_iterator bi;
603 bitmap reg_live_out;
604 unsigned int px;
605 rtx_insn *next;
606 rtx link, *link_loc;
607 bool need_curr_point_incr;
608 HARD_REG_SET last_call_used_reg_set;
610 reg_live_out = df_get_live_out (bb);
611 sparseset_clear (pseudos_live);
612 sparseset_clear (pseudos_live_through_calls);
613 sparseset_clear (pseudos_live_through_setjumps);
614 CLEAR_HARD_REG_SET (last_call_used_reg_set);
615 REG_SET_TO_HARD_REG_SET (hard_regs_live, reg_live_out);
616 AND_COMPL_HARD_REG_SET (hard_regs_live, eliminable_regset);
617 EXECUTE_IF_SET_IN_BITMAP (reg_live_out, FIRST_PSEUDO_REGISTER, j, bi)
618 mark_pseudo_live (j, curr_point);
620 bb_gen_pseudos = &get_bb_data (bb)->gen_pseudos;
621 bb_killed_pseudos = &get_bb_data (bb)->killed_pseudos;
622 bitmap_clear (bb_gen_pseudos);
623 bitmap_clear (bb_killed_pseudos);
624 freq = REG_FREQ_FROM_BB (bb);
626 if (lra_dump_file != NULL)
627 fprintf (lra_dump_file, " BB %d\n", bb->index);
629 /* Scan the code of this basic block, noting which pseudos and hard
630 regs are born or die.
632 Note that this loop treats uninitialized values as live until the
633 beginning of the block. For example, if an instruction uses
634 (reg:DI foo), and only (subreg:SI (reg:DI foo) 0) is ever set,
635 FOO will remain live until the beginning of the block. Likewise
636 if FOO is not set at all. This is unnecessarily pessimistic, but
637 it probably doesn't matter much in practice. */
638 FOR_BB_INSNS_REVERSE_SAFE (bb, curr_insn, next)
640 bool call_p;
641 int dst_regno, src_regno;
642 rtx set;
643 struct lra_insn_reg *reg;
645 if (!NONDEBUG_INSN_P (curr_insn))
646 continue;
648 curr_id = lra_get_insn_recog_data (curr_insn);
649 curr_static_id = curr_id->insn_static_data;
650 if (lra_dump_file != NULL)
651 fprintf (lra_dump_file, " Insn %u: point = %d\n",
652 INSN_UID (curr_insn), curr_point);
654 set = single_set (curr_insn);
656 if (dead_insn_p && set != NULL_RTX
657 && REG_P (SET_DEST (set)) && REGNO (SET_DEST (set)) >= FIRST_PSEUDO_REGISTER
658 && find_reg_note (curr_insn, REG_EH_REGION, NULL_RTX) == NULL_RTX
659 && ! may_trap_p (PATTERN (curr_insn))
660 /* Don't do premature remove of pic offset pseudo as we can
661 start to use it after some reload generation. */
662 && (pic_offset_table_rtx == NULL_RTX
663 || pic_offset_table_rtx != SET_DEST (set)))
665 bool remove_p = true;
667 for (reg = curr_id->regs; reg != NULL; reg = reg->next)
668 if (reg->type != OP_IN && sparseset_bit_p (pseudos_live, reg->regno))
670 remove_p = false;
671 break;
673 for (reg = curr_static_id->hard_regs; reg != NULL; reg = reg->next)
674 if (reg->type != OP_IN)
676 remove_p = false;
677 break;
679 if (remove_p && ! volatile_refs_p (PATTERN (curr_insn)))
681 dst_regno = REGNO (SET_DEST (set));
682 if (lra_dump_file != NULL)
683 fprintf (lra_dump_file, " Deleting dead insn %u\n",
684 INSN_UID (curr_insn));
685 lra_set_insn_deleted (curr_insn);
686 if (lra_reg_info[dst_regno].nrefs == 0)
688 /* There might be some debug insns with the pseudo. */
689 unsigned int uid;
690 rtx_insn *insn;
692 bitmap_copy (&temp_bitmap, &lra_reg_info[dst_regno].insn_bitmap);
693 EXECUTE_IF_SET_IN_BITMAP (&temp_bitmap, 0, uid, bi)
695 insn = lra_insn_recog_data[uid]->insn;
696 lra_substitute_pseudo_within_insn (insn, dst_regno,
697 SET_SRC (set), true);
698 lra_update_insn_regno_info (insn);
701 continue;
705 /* Update max ref width and hard reg usage. */
706 for (reg = curr_id->regs; reg != NULL; reg = reg->next)
708 int i, regno = reg->regno;
710 if (GET_MODE_SIZE (reg->biggest_mode)
711 > GET_MODE_SIZE (lra_reg_info[regno].biggest_mode))
712 lra_reg_info[regno].biggest_mode = reg->biggest_mode;
713 if (regno < FIRST_PSEUDO_REGISTER)
715 lra_hard_reg_usage[regno] += freq;
716 /* A hard register explicitly can be used in small mode,
717 but implicitly it can be used in natural mode as a
718 part of multi-register group. Process this case
719 here. */
720 for (i = 1; i < hard_regno_nregs[regno][reg->biggest_mode]; i++)
721 if (GET_MODE_SIZE (GET_MODE (regno_reg_rtx[regno + i]))
722 > GET_MODE_SIZE (lra_reg_info[regno + i].biggest_mode))
723 lra_reg_info[regno + i].biggest_mode
724 = GET_MODE (regno_reg_rtx[regno + i]);
728 call_p = CALL_P (curr_insn);
729 src_regno = (set != NULL_RTX && REG_P (SET_SRC (set))
730 ? REGNO (SET_SRC (set)) : -1);
731 dst_regno = (set != NULL_RTX && REG_P (SET_DEST (set))
732 ? REGNO (SET_DEST (set)) : -1);
733 if (complete_info_p
734 && src_regno >= 0 && dst_regno >= 0
735 /* Check that source regno does not conflict with
736 destination regno to exclude most impossible
737 preferences. */
738 && (((src_regno >= FIRST_PSEUDO_REGISTER
739 && (! sparseset_bit_p (pseudos_live, src_regno)
740 || (dst_regno >= FIRST_PSEUDO_REGISTER
741 && lra_reg_val_equal_p (src_regno,
742 lra_reg_info[dst_regno].val,
743 lra_reg_info[dst_regno].offset))))
744 || (src_regno < FIRST_PSEUDO_REGISTER
745 && ! TEST_HARD_REG_BIT (hard_regs_live, src_regno)))
746 /* It might be 'inheritance pseudo <- reload pseudo'. */
747 || (src_regno >= lra_constraint_new_regno_start
748 && dst_regno >= lra_constraint_new_regno_start
749 /* Remember to skip special cases where src/dest regnos are
750 the same, e.g. insn SET pattern has matching constraints
751 like =r,0. */
752 && src_regno != dst_regno)))
754 int hard_regno = -1, regno = -1;
756 if (dst_regno >= lra_constraint_new_regno_start
757 && src_regno >= lra_constraint_new_regno_start)
759 /* It might be still an original (non-reload) insn with
760 one unused output and a constraint requiring to use
761 the same reg for input/output operands. In this case
762 dst_regno and src_regno have the same value, we don't
763 need a misleading copy for this case. */
764 if (dst_regno != src_regno)
765 lra_create_copy (dst_regno, src_regno, freq);
767 else if (dst_regno >= lra_constraint_new_regno_start)
769 if ((hard_regno = src_regno) >= FIRST_PSEUDO_REGISTER)
770 hard_regno = reg_renumber[src_regno];
771 regno = dst_regno;
773 else if (src_regno >= lra_constraint_new_regno_start)
775 if ((hard_regno = dst_regno) >= FIRST_PSEUDO_REGISTER)
776 hard_regno = reg_renumber[dst_regno];
777 regno = src_regno;
779 if (regno >= 0 && hard_regno >= 0)
780 lra_setup_reload_pseudo_preferenced_hard_reg
781 (regno, hard_regno, freq);
784 sparseset_clear (start_living);
786 /* Try to avoid unnecessary program point increments, this saves
787 a lot of time in remove_some_program_points_and_update_live_ranges.
788 We only need an increment if something becomes live or dies at this
789 program point. */
790 need_curr_point_incr = false;
792 /* Mark each defined value as live. We need to do this for
793 unused values because they still conflict with quantities
794 that are live at the time of the definition. */
795 for (reg = curr_id->regs; reg != NULL; reg = reg->next)
796 if (reg->type != OP_IN)
798 need_curr_point_incr
799 |= mark_regno_live (reg->regno, reg->biggest_mode,
800 curr_point);
801 check_pseudos_live_through_calls (reg->regno,
802 last_call_used_reg_set);
805 for (reg = curr_static_id->hard_regs; reg != NULL; reg = reg->next)
806 if (reg->type != OP_IN)
807 make_hard_regno_born (reg->regno, false);
809 if (curr_id->arg_hard_regs != NULL)
810 for (i = 0; (regno = curr_id->arg_hard_regs[i]) >= 0; i++)
811 if (regno >= FIRST_PSEUDO_REGISTER)
812 /* It is a clobber. */
813 make_hard_regno_born (regno - FIRST_PSEUDO_REGISTER, false);
815 sparseset_copy (unused_set, start_living);
817 sparseset_clear (start_dying);
819 /* See which defined values die here. */
820 for (reg = curr_id->regs; reg != NULL; reg = reg->next)
821 if (reg->type == OP_OUT && ! reg->early_clobber && ! reg->subreg_p)
822 need_curr_point_incr
823 |= mark_regno_dead (reg->regno, reg->biggest_mode,
824 curr_point);
826 for (reg = curr_static_id->hard_regs; reg != NULL; reg = reg->next)
827 if (reg->type == OP_OUT && ! reg->early_clobber && ! reg->subreg_p)
828 make_hard_regno_dead (reg->regno);
830 if (curr_id->arg_hard_regs != NULL)
831 for (i = 0; (regno = curr_id->arg_hard_regs[i]) >= 0; i++)
832 if (regno >= FIRST_PSEUDO_REGISTER)
833 /* It is a clobber. */
834 make_hard_regno_dead (regno - FIRST_PSEUDO_REGISTER);
836 if (call_p)
838 if (! flag_ipa_ra)
839 COPY_HARD_REG_SET(last_call_used_reg_set, call_used_reg_set);
840 else
842 HARD_REG_SET this_call_used_reg_set;
843 get_call_reg_set_usage (curr_insn, &this_call_used_reg_set,
844 call_used_reg_set);
846 bool flush = (! hard_reg_set_empty_p (last_call_used_reg_set)
847 && ! hard_reg_set_equal_p (last_call_used_reg_set,
848 this_call_used_reg_set));
850 EXECUTE_IF_SET_IN_SPARSESET (pseudos_live, j)
852 IOR_HARD_REG_SET (lra_reg_info[j].actual_call_used_reg_set,
853 this_call_used_reg_set);
854 if (flush)
855 check_pseudos_live_through_calls
856 (j, last_call_used_reg_set);
858 COPY_HARD_REG_SET(last_call_used_reg_set, this_call_used_reg_set);
861 sparseset_ior (pseudos_live_through_calls,
862 pseudos_live_through_calls, pseudos_live);
863 if (cfun->has_nonlocal_label
864 || find_reg_note (curr_insn, REG_SETJMP,
865 NULL_RTX) != NULL_RTX)
866 sparseset_ior (pseudos_live_through_setjumps,
867 pseudos_live_through_setjumps, pseudos_live);
870 /* Increment the current program point if we must. */
871 if (need_curr_point_incr)
872 next_program_point (curr_point, freq);
874 sparseset_clear (start_living);
876 need_curr_point_incr = false;
878 /* Mark each used value as live. */
879 for (reg = curr_id->regs; reg != NULL; reg = reg->next)
880 if (reg->type == OP_IN)
882 need_curr_point_incr
883 |= mark_regno_live (reg->regno, reg->biggest_mode,
884 curr_point);
885 check_pseudos_live_through_calls (reg->regno,
886 last_call_used_reg_set);
889 for (reg = curr_static_id->hard_regs; reg != NULL; reg = reg->next)
890 if (reg->type == OP_IN)
891 make_hard_regno_born (reg->regno, false);
893 if (curr_id->arg_hard_regs != NULL)
894 /* Make argument hard registers live. Don't create conflict
895 of used REAL_PIC_OFFSET_TABLE_REGNUM and the pic pseudo. */
896 for (i = 0; (regno = curr_id->arg_hard_regs[i]) >= 0; i++)
897 if (regno < FIRST_PSEUDO_REGISTER)
898 make_hard_regno_born (regno, true);
900 sparseset_and_compl (dead_set, start_living, start_dying);
902 /* Mark early clobber outputs dead. */
903 for (reg = curr_id->regs; reg != NULL; reg = reg->next)
904 if (reg->type == OP_OUT && reg->early_clobber && ! reg->subreg_p)
905 need_curr_point_incr
906 |= mark_regno_dead (reg->regno, reg->biggest_mode,
907 curr_point);
909 for (reg = curr_static_id->hard_regs; reg != NULL; reg = reg->next)
910 if (reg->type == OP_OUT && reg->early_clobber && ! reg->subreg_p)
911 make_hard_regno_dead (reg->regno);
913 if (need_curr_point_incr)
914 next_program_point (curr_point, freq);
916 /* Update notes. */
917 for (link_loc = &REG_NOTES (curr_insn); (link = *link_loc) != NULL_RTX;)
919 if (REG_NOTE_KIND (link) != REG_DEAD
920 && REG_NOTE_KIND (link) != REG_UNUSED)
922 else if (REG_P (XEXP (link, 0)))
924 regno = REGNO (XEXP (link, 0));
925 if ((REG_NOTE_KIND (link) == REG_DEAD
926 && ! sparseset_bit_p (dead_set, regno))
927 || (REG_NOTE_KIND (link) == REG_UNUSED
928 && ! sparseset_bit_p (unused_set, regno)))
930 *link_loc = XEXP (link, 1);
931 continue;
933 if (REG_NOTE_KIND (link) == REG_DEAD)
934 sparseset_clear_bit (dead_set, regno);
935 else if (REG_NOTE_KIND (link) == REG_UNUSED)
936 sparseset_clear_bit (unused_set, regno);
938 link_loc = &XEXP (link, 1);
940 EXECUTE_IF_SET_IN_SPARSESET (dead_set, j)
941 add_reg_note (curr_insn, REG_DEAD, regno_reg_rtx[j]);
942 EXECUTE_IF_SET_IN_SPARSESET (unused_set, j)
943 add_reg_note (curr_insn, REG_UNUSED, regno_reg_rtx[j]);
946 if (bb_has_eh_pred (bb))
947 for (j = 0; ; ++j)
949 unsigned int regno = EH_RETURN_DATA_REGNO (j);
951 if (regno == INVALID_REGNUM)
952 break;
953 make_hard_regno_born (regno, false);
956 /* Pseudos can't go in stack regs at the start of a basic block that
957 is reached by an abnormal edge. Likewise for call clobbered regs,
958 because caller-save, fixup_abnormal_edges and possibly the table
959 driven EH machinery are not quite ready to handle such pseudos
960 live across such edges. */
961 if (bb_has_abnormal_pred (bb))
963 #ifdef STACK_REGS
964 EXECUTE_IF_SET_IN_SPARSESET (pseudos_live, px)
965 lra_reg_info[px].no_stack_p = true;
966 for (px = FIRST_STACK_REG; px <= LAST_STACK_REG; px++)
967 make_hard_regno_born (px, false);
968 #endif
969 /* No need to record conflicts for call clobbered regs if we
970 have nonlocal labels around, as we don't ever try to
971 allocate such regs in this case. */
972 if (!cfun->has_nonlocal_label
973 && has_abnormal_call_or_eh_pred_edge_p (bb))
974 for (px = 0; px < FIRST_PSEUDO_REGISTER; px++)
975 if (call_used_regs[px]
976 #ifdef REAL_PIC_OFFSET_TABLE_REGNUM
977 /* We should create a conflict of PIC pseudo with PIC
978 hard reg as PIC hard reg can have a wrong value after
979 jump described by the abnormal edge. In this case we
980 can not allocate PIC hard reg to PIC pseudo as PIC
981 pseudo will also have a wrong value. */
982 || (px == REAL_PIC_OFFSET_TABLE_REGNUM
983 && pic_offset_table_rtx != NULL_RTX
984 && REGNO (pic_offset_table_rtx) >= FIRST_PSEUDO_REGISTER)
985 #endif
987 make_hard_regno_born (px, false);
990 bool live_change_p = false;
991 /* Check if bb border live info was changed. */
992 unsigned int live_pseudos_num = 0;
993 EXECUTE_IF_SET_IN_BITMAP (df_get_live_in (bb),
994 FIRST_PSEUDO_REGISTER, j, bi)
996 live_pseudos_num++;
997 if (! sparseset_bit_p (pseudos_live, j))
999 live_change_p = true;
1000 if (lra_dump_file != NULL)
1001 fprintf (lra_dump_file,
1002 " r%d is removed as live at bb%d start\n", j, bb->index);
1003 break;
1006 if (! live_change_p
1007 && sparseset_cardinality (pseudos_live) != live_pseudos_num)
1009 live_change_p = true;
1010 if (lra_dump_file != NULL)
1011 EXECUTE_IF_SET_IN_SPARSESET (pseudos_live, j)
1012 if (! bitmap_bit_p (df_get_live_in (bb), j))
1013 fprintf (lra_dump_file,
1014 " r%d is added to live at bb%d start\n", j, bb->index);
1016 /* See if we'll need an increment at the end of this basic block.
1017 An increment is needed if the PSEUDOS_LIVE set is not empty,
1018 to make sure the finish points are set up correctly. */
1019 need_curr_point_incr = (sparseset_cardinality (pseudos_live) > 0);
1021 EXECUTE_IF_SET_IN_SPARSESET (pseudos_live, i)
1022 mark_pseudo_dead (i, curr_point);
1024 EXECUTE_IF_SET_IN_BITMAP (df_get_live_in (bb), FIRST_PSEUDO_REGISTER, j, bi)
1026 if (sparseset_cardinality (pseudos_live_through_calls) == 0)
1027 break;
1028 if (sparseset_bit_p (pseudos_live_through_calls, j))
1029 check_pseudos_live_through_calls (j, last_call_used_reg_set);
1032 if (need_curr_point_incr)
1033 next_program_point (curr_point, freq);
1035 return live_change_p;
1038 /* Compress pseudo live ranges by removing program points where
1039 nothing happens. Complexity of many algorithms in LRA is linear
1040 function of program points number. To speed up the code we try to
1041 minimize the number of the program points here. */
1042 static void
1043 remove_some_program_points_and_update_live_ranges (void)
1045 unsigned i;
1046 int n, max_regno;
1047 int *map;
1048 lra_live_range_t r, prev_r, next_r;
1049 sbitmap_iterator sbi;
1050 bool born_p, dead_p, prev_born_p, prev_dead_p;
1052 auto_sbitmap born (lra_live_max_point);
1053 auto_sbitmap dead (lra_live_max_point);
1054 bitmap_clear (born);
1055 bitmap_clear (dead);
1056 max_regno = max_reg_num ();
1057 for (i = FIRST_PSEUDO_REGISTER; i < (unsigned) max_regno; i++)
1059 for (r = lra_reg_info[i].live_ranges; r != NULL; r = r->next)
1061 lra_assert (r->start <= r->finish);
1062 bitmap_set_bit (born, r->start);
1063 bitmap_set_bit (dead, r->finish);
1066 auto_sbitmap born_or_dead (lra_live_max_point);
1067 bitmap_ior (born_or_dead, born, dead);
1068 map = XCNEWVEC (int, lra_live_max_point);
1069 n = -1;
1070 prev_born_p = prev_dead_p = false;
1071 EXECUTE_IF_SET_IN_BITMAP (born_or_dead, 0, i, sbi)
1073 born_p = bitmap_bit_p (born, i);
1074 dead_p = bitmap_bit_p (dead, i);
1075 if ((prev_born_p && ! prev_dead_p && born_p && ! dead_p)
1076 || (prev_dead_p && ! prev_born_p && dead_p && ! born_p))
1078 map[i] = n;
1079 lra_point_freq[n] = MAX (lra_point_freq[n], lra_point_freq[i]);
1081 else
1083 map[i] = ++n;
1084 lra_point_freq[n] = lra_point_freq[i];
1086 prev_born_p = born_p;
1087 prev_dead_p = dead_p;
1089 n++;
1090 if (lra_dump_file != NULL)
1091 fprintf (lra_dump_file, "Compressing live ranges: from %d to %d - %d%%\n",
1092 lra_live_max_point, n, 100 * n / lra_live_max_point);
1093 if (n < lra_live_max_point)
1095 lra_live_max_point = n;
1096 for (i = FIRST_PSEUDO_REGISTER; i < (unsigned) max_regno; i++)
1098 for (prev_r = NULL, r = lra_reg_info[i].live_ranges;
1099 r != NULL;
1100 r = next_r)
1102 next_r = r->next;
1103 r->start = map[r->start];
1104 r->finish = map[r->finish];
1105 if (prev_r == NULL || prev_r->start > r->finish + 1)
1107 prev_r = r;
1108 continue;
1110 prev_r->start = r->start;
1111 prev_r->next = next_r;
1112 lra_live_range_pool.remove (r);
1116 free (map);
1119 /* Print live ranges R to file F. */
1120 void
1121 lra_print_live_range_list (FILE *f, lra_live_range_t r)
1123 for (; r != NULL; r = r->next)
1124 fprintf (f, " [%d..%d]", r->start, r->finish);
1125 fprintf (f, "\n");
1128 DEBUG_FUNCTION void
1129 debug (lra_live_range &ref)
1131 lra_print_live_range_list (stderr, &ref);
1134 DEBUG_FUNCTION void
1135 debug (lra_live_range *ptr)
1137 if (ptr)
1138 debug (*ptr);
1139 else
1140 fprintf (stderr, "<nil>\n");
1143 /* Print live ranges R to stderr. */
1144 void
1145 lra_debug_live_range_list (lra_live_range_t r)
1147 lra_print_live_range_list (stderr, r);
1150 /* Print live ranges of pseudo REGNO to file F. */
1151 static void
1152 print_pseudo_live_ranges (FILE *f, int regno)
1154 if (lra_reg_info[regno].live_ranges == NULL)
1155 return;
1156 fprintf (f, " r%d:", regno);
1157 lra_print_live_range_list (f, lra_reg_info[regno].live_ranges);
1160 /* Print live ranges of pseudo REGNO to stderr. */
1161 void
1162 lra_debug_pseudo_live_ranges (int regno)
1164 print_pseudo_live_ranges (stderr, regno);
1167 /* Print live ranges of all pseudos to file F. */
1168 static void
1169 print_live_ranges (FILE *f)
1171 int i, max_regno;
1173 max_regno = max_reg_num ();
1174 for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
1175 print_pseudo_live_ranges (f, i);
1178 /* Print live ranges of all pseudos to stderr. */
1179 void
1180 lra_debug_live_ranges (void)
1182 print_live_ranges (stderr);
1185 /* Compress pseudo live ranges. */
1186 static void
1187 compress_live_ranges (void)
1189 remove_some_program_points_and_update_live_ranges ();
1190 if (lra_dump_file != NULL)
1192 fprintf (lra_dump_file, "Ranges after the compression:\n");
1193 print_live_ranges (lra_dump_file);
1199 /* The number of the current live range pass. */
1200 int lra_live_range_iter;
1202 /* The function creates live ranges only for memory pseudos (or for
1203 all ones if ALL_P), set up CONFLICT_HARD_REGS for the pseudos. It
1204 also does dead insn elimination if DEAD_INSN_P and global live
1205 analysis only for pseudos and only if the pseudo live info was
1206 changed on a BB border. Return TRUE if the live info was
1207 changed. */
1208 static bool
1209 lra_create_live_ranges_1 (bool all_p, bool dead_insn_p)
1211 basic_block bb;
1212 int i, hard_regno, max_regno = max_reg_num ();
1213 int curr_point;
1214 bool bb_live_change_p, have_referenced_pseudos = false;
1216 timevar_push (TV_LRA_CREATE_LIVE_RANGES);
1218 complete_info_p = all_p;
1219 if (lra_dump_file != NULL)
1220 fprintf (lra_dump_file,
1221 "\n********** Pseudo live ranges #%d: **********\n\n",
1222 ++lra_live_range_iter);
1223 memset (lra_hard_reg_usage, 0, sizeof (lra_hard_reg_usage));
1224 for (i = 0; i < max_regno; i++)
1226 lra_reg_info[i].live_ranges = NULL;
1227 CLEAR_HARD_REG_SET (lra_reg_info[i].conflict_hard_regs);
1228 lra_reg_info[i].preferred_hard_regno1 = -1;
1229 lra_reg_info[i].preferred_hard_regno2 = -1;
1230 lra_reg_info[i].preferred_hard_regno_profit1 = 0;
1231 lra_reg_info[i].preferred_hard_regno_profit2 = 0;
1232 #ifdef STACK_REGS
1233 lra_reg_info[i].no_stack_p = false;
1234 #endif
1235 /* The biggest mode is already set but its value might be to
1236 conservative because of recent transformation. Here in this
1237 file we recalculate it again as it costs practically
1238 nothing. */
1239 if (i >= FIRST_PSEUDO_REGISTER && regno_reg_rtx[i] != NULL_RTX)
1240 lra_reg_info[i].biggest_mode = GET_MODE (regno_reg_rtx[i]);
1241 else
1242 lra_reg_info[i].biggest_mode = VOIDmode;
1243 lra_reg_info[i].call_p = false;
1244 if (i >= FIRST_PSEUDO_REGISTER
1245 && lra_reg_info[i].nrefs != 0)
1247 if ((hard_regno = reg_renumber[i]) >= 0)
1248 lra_hard_reg_usage[hard_regno] += lra_reg_info[i].freq;
1249 have_referenced_pseudos = true;
1252 lra_free_copies ();
1254 /* Under some circumstances, we can have functions without pseudo
1255 registers. For such functions, lra_live_max_point will be 0,
1256 see e.g. PR55604, and there's nothing more to do for us here. */
1257 if (! have_referenced_pseudos)
1259 timevar_pop (TV_LRA_CREATE_LIVE_RANGES);
1260 return false;
1263 pseudos_live = sparseset_alloc (max_regno);
1264 pseudos_live_through_calls = sparseset_alloc (max_regno);
1265 pseudos_live_through_setjumps = sparseset_alloc (max_regno);
1266 start_living = sparseset_alloc (max_regno);
1267 start_dying = sparseset_alloc (max_regno);
1268 dead_set = sparseset_alloc (max_regno);
1269 unused_set = sparseset_alloc (max_regno);
1270 curr_point = 0;
1271 unsigned new_length = get_max_uid () * 2;
1272 point_freq_vec.truncate (0);
1273 point_freq_vec.reserve_exact (new_length);
1274 lra_point_freq = point_freq_vec.address ();
1275 int *post_order_rev_cfg = XNEWVEC (int, last_basic_block_for_fn (cfun));
1276 int n_blocks_inverted = inverted_post_order_compute (post_order_rev_cfg);
1277 lra_assert (n_blocks_inverted == n_basic_blocks_for_fn (cfun));
1278 bb_live_change_p = false;
1279 for (i = n_blocks_inverted - 1; i >= 0; --i)
1281 bb = BASIC_BLOCK_FOR_FN (cfun, post_order_rev_cfg[i]);
1282 if (bb == EXIT_BLOCK_PTR_FOR_FN (cfun) || bb
1283 == ENTRY_BLOCK_PTR_FOR_FN (cfun))
1284 continue;
1285 if (process_bb_lives (bb, curr_point, dead_insn_p))
1286 bb_live_change_p = true;
1288 if (bb_live_change_p)
1290 /* We need to clear pseudo live info as some pseudos can
1291 disappear, e.g. pseudos with used equivalences. */
1292 FOR_EACH_BB_FN (bb, cfun)
1294 bitmap_clear_range (df_get_live_in (bb), FIRST_PSEUDO_REGISTER,
1295 max_regno - FIRST_PSEUDO_REGISTER);
1296 bitmap_clear_range (df_get_live_out (bb), FIRST_PSEUDO_REGISTER,
1297 max_regno - FIRST_PSEUDO_REGISTER);
1299 /* As we did not change CFG since LRA start we can use
1300 DF-infrastructure solver to solve live data flow problem. */
1301 df_simple_dataflow
1302 (DF_BACKWARD, NULL, live_con_fun_0, live_con_fun_n,
1303 live_trans_fun, &all_blocks,
1304 df_get_postorder (DF_BACKWARD), df_get_n_blocks (DF_BACKWARD));
1305 if (lra_dump_file != NULL)
1307 fprintf (lra_dump_file,
1308 "Global pseudo live data have been updated:\n");
1309 basic_block bb;
1310 FOR_EACH_BB_FN (bb, cfun)
1312 bb_data_t bb_info = get_bb_data (bb);
1313 bitmap bb_livein = df_get_live_in (bb);
1314 bitmap bb_liveout = df_get_live_out (bb);
1316 fprintf (lra_dump_file, "\nBB %d:\n", bb->index);
1317 lra_dump_bitmap_with_title (" gen:",
1318 &bb_info->gen_pseudos, bb->index);
1319 lra_dump_bitmap_with_title (" killed:",
1320 &bb_info->killed_pseudos, bb->index);
1321 lra_dump_bitmap_with_title (" livein:", bb_livein, bb->index);
1322 lra_dump_bitmap_with_title (" liveout:", bb_liveout, bb->index);
1326 free (post_order_rev_cfg);
1327 lra_live_max_point = curr_point;
1328 if (lra_dump_file != NULL)
1329 print_live_ranges (lra_dump_file);
1330 /* Clean up. */
1331 sparseset_free (unused_set);
1332 sparseset_free (dead_set);
1333 sparseset_free (start_dying);
1334 sparseset_free (start_living);
1335 sparseset_free (pseudos_live_through_calls);
1336 sparseset_free (pseudos_live_through_setjumps);
1337 sparseset_free (pseudos_live);
1338 compress_live_ranges ();
1339 timevar_pop (TV_LRA_CREATE_LIVE_RANGES);
1340 return bb_live_change_p;
1343 /* The main entry function creates live-ranges and other live info
1344 necessary for the assignment sub-pass. It uses
1345 lra_creates_live_ranges_1 -- so read comments for the
1346 function. */
1347 void
1348 lra_create_live_ranges (bool all_p, bool dead_insn_p)
1350 if (! lra_create_live_ranges_1 (all_p, dead_insn_p))
1351 return;
1352 if (lra_dump_file != NULL)
1353 fprintf (lra_dump_file, "Live info was changed -- recalculate it\n");
1354 /* Live info was changed on a bb border. It means that some info,
1355 e.g. about conflict regs, calls crossed, and live ranges may be
1356 wrong. We need this info for allocation. So recalculate it
1357 again but without removing dead insns which can change live info
1358 again. Repetitive live range calculations are expensive therefore
1359 we stop here as we already have correct info although some
1360 improvement in rare cases could be possible on this sub-pass if
1361 we do dead insn elimination again (still the improvement may
1362 happen later). */
1363 lra_clear_live_ranges ();
1364 bool res = lra_create_live_ranges_1 (all_p, false);
1365 lra_assert (! res);
1368 /* Finish all live ranges. */
1369 void
1370 lra_clear_live_ranges (void)
1372 int i;
1374 for (i = 0; i < max_reg_num (); i++)
1375 free_live_range_list (lra_reg_info[i].live_ranges);
1376 point_freq_vec.release ();
1379 /* Initialize live ranges data once per function. */
1380 void
1381 lra_live_ranges_init (void)
1383 bitmap_initialize (&temp_bitmap, &reg_obstack);
1384 initiate_live_solver ();
1387 /* Finish live ranges data once per function. */
1388 void
1389 lra_live_ranges_finish (void)
1391 finish_live_solver ();
1392 bitmap_clear (&temp_bitmap);
1393 lra_live_range_pool.release ();