1 /* Build live ranges for pseudos.
2 Copyright (C) 2010-2018 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
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
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. */
30 #include "coretypes.h"
38 #include "insn-config.h"
43 #include "sparseset.h"
47 /* Program points are enumerated by numbers from range
48 0..LRA_LIVE_MAX_POINT-1. There are approximately two times more
49 program points than insns. Program points are places in the
50 program where liveness info can be changed. In most general case
51 (there are more complicated cases too) some program points
52 correspond to places where input operand dies and other ones
53 correspond to places where output operands are born. */
54 int lra_live_max_point
;
56 /* Accumulated execution frequency of all references for each hard
58 int lra_hard_reg_usage
[FIRST_PSEUDO_REGISTER
];
60 /* A global flag whose true value says to build live ranges for all
61 pseudos, otherwise the live ranges only for pseudos got memory is
62 build. True value means also building copies and setting up hard
63 register preferences. The complete info is necessary only for the
64 assignment pass. The complete info is not needed for the
65 coalescing and spill passes. */
66 static bool complete_info_p
;
68 /* Pseudos live at current point in the RTL scan. */
69 static sparseset pseudos_live
;
71 /* Pseudos probably living through calls and setjumps. As setjump is
72 a call too, if a bit in PSEUDOS_LIVE_THROUGH_SETJUMPS is set up
73 then the corresponding bit in PSEUDOS_LIVE_THROUGH_CALLS is set up
74 too. These data are necessary for cases when only one subreg of a
75 multi-reg pseudo is set up after a call. So we decide it is
76 probably live when traversing bb backward. We are sure about
77 living when we see its usage or definition of the pseudo. */
78 static sparseset pseudos_live_through_calls
;
79 static sparseset pseudos_live_through_setjumps
;
81 /* Set of hard regs (except eliminable ones) currently live. */
82 static HARD_REG_SET hard_regs_live
;
84 /* Set of pseudos and hard registers start living/dying in the current
85 insn. These sets are used to update REG_DEAD and REG_UNUSED notes
87 static sparseset start_living
, start_dying
;
89 /* Set of pseudos and hard regs dead and unused in the current
91 static sparseset unused_set
, dead_set
;
93 /* Bitmap used for holding intermediate bitmap operation results. */
94 static bitmap_head temp_bitmap
;
96 /* Pool for pseudo live ranges. */
97 static object_allocator
<lra_live_range
> lra_live_range_pool ("live ranges");
99 /* Free live range list LR. */
101 free_live_range_list (lra_live_range_t lr
)
103 lra_live_range_t next
;
108 lra_live_range_pool
.remove (lr
);
113 /* Create and return pseudo live range with given attributes. */
114 static lra_live_range_t
115 create_live_range (int regno
, int start
, int finish
, lra_live_range_t next
)
117 lra_live_range_t p
= lra_live_range_pool
.allocate ();
125 /* Copy live range R and return the result. */
126 static lra_live_range_t
127 copy_live_range (lra_live_range_t r
)
129 return new (lra_live_range_pool
) lra_live_range (*r
);
132 /* Copy live range list given by its head R and return the result. */
134 lra_copy_live_range_list (lra_live_range_t r
)
136 lra_live_range_t p
, first
, *chain
;
139 for (chain
= &first
; r
!= NULL
; r
= r
->next
)
141 p
= copy_live_range (r
);
148 /* Merge *non-intersected* ranges R1 and R2 and returns the result.
149 The function maintains the order of ranges and tries to minimize
150 size of the result range list. Ranges R1 and R2 may not be used
153 lra_merge_live_ranges (lra_live_range_t r1
, lra_live_range_t r2
)
155 lra_live_range_t first
, last
;
161 for (first
= last
= NULL
; r1
!= NULL
&& r2
!= NULL
;)
163 if (r1
->start
< r2
->start
)
166 if (r1
->start
== r2
->finish
+ 1)
168 /* Joint ranges: merge r1 and r2 into r1. */
169 r1
->start
= r2
->start
;
170 lra_live_range_t temp
= r2
;
172 lra_live_range_pool
.remove (temp
);
176 gcc_assert (r2
->finish
+ 1 < r1
->start
);
177 /* Add r1 to the result. */
197 lra_assert (r2
!= NULL
);
206 /* Return TRUE if live ranges R1 and R2 intersect. */
208 lra_intersected_live_ranges_p (lra_live_range_t r1
, lra_live_range_t r2
)
210 /* Remember the live ranges are always kept ordered. */
211 while (r1
!= NULL
&& r2
!= NULL
)
213 if (r1
->start
> r2
->finish
)
215 else if (r2
->start
> r1
->finish
)
223 /* The corresponding bitmaps of BB currently being processed. */
224 static bitmap bb_killed_pseudos
, bb_gen_pseudos
;
226 /* The function processing birth of hard register REGNO. It updates
227 living hard regs, START_LIVING, and conflict hard regs for living
228 pseudos. Conflict hard regs for the pic pseudo is not updated if
229 REGNO is REAL_PIC_OFFSET_TABLE_REGNUM and CHECK_PIC_PSEUDO_P is
232 make_hard_regno_born (int regno
, bool check_pic_pseudo_p ATTRIBUTE_UNUSED
)
236 lra_assert (regno
< FIRST_PSEUDO_REGISTER
);
237 if (TEST_HARD_REG_BIT (hard_regs_live
, regno
))
239 SET_HARD_REG_BIT (hard_regs_live
, regno
);
240 sparseset_set_bit (start_living
, regno
);
241 EXECUTE_IF_SET_IN_SPARSESET (pseudos_live
, i
)
242 #ifdef REAL_PIC_OFFSET_TABLE_REGNUM
243 if (! check_pic_pseudo_p
244 || regno
!= REAL_PIC_OFFSET_TABLE_REGNUM
245 || pic_offset_table_rtx
== NULL
246 || i
!= REGNO (pic_offset_table_rtx
))
248 SET_HARD_REG_BIT (lra_reg_info
[i
].conflict_hard_regs
, regno
);
249 if (fixed_regs
[regno
] || TEST_HARD_REG_BIT (hard_regs_spilled_into
, regno
))
250 bitmap_set_bit (bb_gen_pseudos
, regno
);
253 /* Process the death of hard register REGNO. This updates
254 hard_regs_live and START_DYING. */
256 make_hard_regno_dead (int regno
)
258 lra_assert (regno
< FIRST_PSEUDO_REGISTER
);
259 if (! TEST_HARD_REG_BIT (hard_regs_live
, regno
))
261 sparseset_set_bit (start_dying
, regno
);
262 CLEAR_HARD_REG_BIT (hard_regs_live
, regno
);
263 if (fixed_regs
[regno
] || TEST_HARD_REG_BIT (hard_regs_spilled_into
, regno
))
265 bitmap_clear_bit (bb_gen_pseudos
, regno
);
266 bitmap_set_bit (bb_killed_pseudos
, regno
);
270 /* Mark pseudo REGNO as living at program point POINT, update conflicting
271 hard registers of the pseudo and START_LIVING, and start a new live
272 range for the pseudo corresponding to REGNO if it is necessary. */
274 mark_pseudo_live (int regno
, int point
)
278 lra_assert (regno
>= FIRST_PSEUDO_REGISTER
);
279 lra_assert (! sparseset_bit_p (pseudos_live
, regno
));
280 sparseset_set_bit (pseudos_live
, regno
);
281 IOR_HARD_REG_SET (lra_reg_info
[regno
].conflict_hard_regs
, hard_regs_live
);
283 if ((complete_info_p
|| lra_get_regno_hard_regno (regno
) < 0)
284 && ((p
= lra_reg_info
[regno
].live_ranges
) == NULL
285 || (p
->finish
!= point
&& p
->finish
+ 1 != point
)))
286 lra_reg_info
[regno
].live_ranges
287 = create_live_range (regno
, point
, -1, p
);
288 sparseset_set_bit (start_living
, regno
);
291 /* Mark pseudo REGNO as not living at program point POINT and update
293 This finishes the current live range for the pseudo corresponding
296 mark_pseudo_dead (int regno
, int point
)
300 lra_assert (regno
>= FIRST_PSEUDO_REGISTER
);
301 lra_assert (sparseset_bit_p (pseudos_live
, regno
));
302 sparseset_clear_bit (pseudos_live
, regno
);
303 sparseset_set_bit (start_dying
, regno
);
304 if (complete_info_p
|| lra_get_regno_hard_regno (regno
) < 0)
306 p
= lra_reg_info
[regno
].live_ranges
;
307 lra_assert (p
!= NULL
);
312 /* Mark register REGNO (pseudo or hard register) in MODE as live at
313 program point POINT. Update BB_GEN_PSEUDOS.
314 Return TRUE if the liveness tracking sets were modified, or FALSE
315 if nothing changed. */
317 mark_regno_live (int regno
, machine_mode mode
, int point
)
320 bool changed
= false;
322 if (regno
< FIRST_PSEUDO_REGISTER
)
324 for (last
= end_hard_regno (mode
, regno
); regno
< last
; regno
++)
325 make_hard_regno_born (regno
, false);
329 if (! sparseset_bit_p (pseudos_live
, regno
))
331 mark_pseudo_live (regno
, point
);
334 bitmap_set_bit (bb_gen_pseudos
, regno
);
340 /* Mark register REGNO in MODE as dead at program point POINT. Update
341 BB_GEN_PSEUDOS and BB_KILLED_PSEUDOS. Return TRUE if the liveness
342 tracking sets were modified, or FALSE if nothing changed. */
344 mark_regno_dead (int regno
, machine_mode mode
, int point
)
347 bool changed
= false;
349 if (regno
< FIRST_PSEUDO_REGISTER
)
351 for (last
= end_hard_regno (mode
, regno
); regno
< last
; regno
++)
352 make_hard_regno_dead (regno
);
356 if (sparseset_bit_p (pseudos_live
, regno
))
358 mark_pseudo_dead (regno
, point
);
361 bitmap_clear_bit (bb_gen_pseudos
, regno
);
362 bitmap_set_bit (bb_killed_pseudos
, regno
);
369 /* This page contains code for making global live analysis of pseudos.
370 The code works only when pseudo live info is changed on a BB
371 border. That might be a consequence of some global transformations
372 in LRA, e.g. PIC pseudo reuse or rematerialization. */
374 /* Structure describing local BB data used for pseudo
376 struct bb_data_pseudos
378 /* Basic block about which the below data are. */
380 bitmap_head killed_pseudos
; /* pseudos killed in the BB. */
381 bitmap_head gen_pseudos
; /* pseudos generated in the BB. */
384 /* Array for all BB data. Indexed by the corresponding BB index. */
385 typedef struct bb_data_pseudos
*bb_data_t
;
387 /* All basic block data are referred through the following array. */
388 static bb_data_t bb_data
;
390 /* Two small functions for access to the bb data. */
391 static inline bb_data_t
392 get_bb_data (basic_block bb
)
394 return &bb_data
[(bb
)->index
];
397 static inline bb_data_t
398 get_bb_data_by_index (int index
)
400 return &bb_data
[index
];
403 /* Bitmap with all hard regs. */
404 static bitmap_head all_hard_regs_bitmap
;
406 /* The transfer function used by the DF equation solver to propagate
407 live info through block with BB_INDEX according to the following
410 bb.livein = (bb.liveout - bb.kill) OR bb.gen
413 live_trans_fun (int bb_index
)
415 basic_block bb
= get_bb_data_by_index (bb_index
)->bb
;
416 bitmap bb_liveout
= df_get_live_out (bb
);
417 bitmap bb_livein
= df_get_live_in (bb
);
418 bb_data_t bb_info
= get_bb_data (bb
);
420 bitmap_and_compl (&temp_bitmap
, bb_liveout
, &all_hard_regs_bitmap
);
421 return bitmap_ior_and_compl (bb_livein
, &bb_info
->gen_pseudos
,
422 &temp_bitmap
, &bb_info
->killed_pseudos
);
425 /* The confluence function used by the DF equation solver to set up
426 live info for a block BB without predecessor. */
428 live_con_fun_0 (basic_block bb
)
430 bitmap_and_into (df_get_live_out (bb
), &all_hard_regs_bitmap
);
433 /* The confluence function used by the DF equation solver to propagate
434 live info from successor to predecessor on edge E according to the
437 bb.liveout = 0 for entry block | OR (livein of successors)
440 live_con_fun_n (edge e
)
442 basic_block bb
= e
->src
;
443 basic_block dest
= e
->dest
;
444 bitmap bb_liveout
= df_get_live_out (bb
);
445 bitmap dest_livein
= df_get_live_in (dest
);
447 return bitmap_ior_and_compl_into (bb_liveout
,
448 dest_livein
, &all_hard_regs_bitmap
);
451 /* Indexes of all function blocks. */
452 static bitmap_head all_blocks
;
454 /* Allocate and initialize data needed for global pseudo live
457 initiate_live_solver (void)
459 bitmap_initialize (&all_hard_regs_bitmap
, ®_obstack
);
460 bitmap_set_range (&all_hard_regs_bitmap
, 0, FIRST_PSEUDO_REGISTER
);
461 bb_data
= XNEWVEC (struct bb_data_pseudos
, last_basic_block_for_fn (cfun
));
462 bitmap_initialize (&all_blocks
, ®_obstack
);
465 FOR_ALL_BB_FN (bb
, cfun
)
467 bb_data_t bb_info
= get_bb_data (bb
);
469 bitmap_initialize (&bb_info
->killed_pseudos
, ®_obstack
);
470 bitmap_initialize (&bb_info
->gen_pseudos
, ®_obstack
);
471 bitmap_set_bit (&all_blocks
, bb
->index
);
475 /* Free all data needed for global pseudo live analysis. */
477 finish_live_solver (void)
481 bitmap_clear (&all_blocks
);
482 FOR_ALL_BB_FN (bb
, cfun
)
484 bb_data_t bb_info
= get_bb_data (bb
);
485 bitmap_clear (&bb_info
->killed_pseudos
);
486 bitmap_clear (&bb_info
->gen_pseudos
);
489 bitmap_clear (&all_hard_regs_bitmap
);
494 /* Insn currently scanned. */
495 static rtx_insn
*curr_insn
;
497 static lra_insn_recog_data_t curr_id
;
498 /* The insn static data. */
499 static struct lra_static_insn_data
*curr_static_id
;
501 /* Vec containing execution frequencies of program points. */
502 static vec
<int> point_freq_vec
;
504 /* The start of the above vector elements. */
507 /* Increment the current program point POINT to the next point which has
508 execution frequency FREQ. */
510 next_program_point (int &point
, int freq
)
512 point_freq_vec
.safe_push (freq
);
513 lra_point_freq
= point_freq_vec
.address ();
517 /* Update the preference of HARD_REGNO for pseudo REGNO by PROFIT. */
519 lra_setup_reload_pseudo_preferenced_hard_reg (int regno
,
520 int hard_regno
, int profit
)
522 lra_assert (regno
>= lra_constraint_new_regno_start
);
523 if (lra_reg_info
[regno
].preferred_hard_regno1
== hard_regno
)
524 lra_reg_info
[regno
].preferred_hard_regno_profit1
+= profit
;
525 else if (lra_reg_info
[regno
].preferred_hard_regno2
== hard_regno
)
526 lra_reg_info
[regno
].preferred_hard_regno_profit2
+= profit
;
527 else if (lra_reg_info
[regno
].preferred_hard_regno1
< 0)
529 lra_reg_info
[regno
].preferred_hard_regno1
= hard_regno
;
530 lra_reg_info
[regno
].preferred_hard_regno_profit1
= profit
;
532 else if (lra_reg_info
[regno
].preferred_hard_regno2
< 0
533 || profit
> lra_reg_info
[regno
].preferred_hard_regno_profit2
)
535 lra_reg_info
[regno
].preferred_hard_regno2
= hard_regno
;
536 lra_reg_info
[regno
].preferred_hard_regno_profit2
= profit
;
540 /* Keep the 1st hard regno as more profitable. */
541 if (lra_reg_info
[regno
].preferred_hard_regno1
>= 0
542 && lra_reg_info
[regno
].preferred_hard_regno2
>= 0
543 && (lra_reg_info
[regno
].preferred_hard_regno_profit2
544 > lra_reg_info
[regno
].preferred_hard_regno_profit1
))
546 std::swap (lra_reg_info
[regno
].preferred_hard_regno1
,
547 lra_reg_info
[regno
].preferred_hard_regno2
);
548 std::swap (lra_reg_info
[regno
].preferred_hard_regno_profit1
,
549 lra_reg_info
[regno
].preferred_hard_regno_profit2
);
551 if (lra_dump_file
!= NULL
)
553 if ((hard_regno
= lra_reg_info
[regno
].preferred_hard_regno1
) >= 0)
554 fprintf (lra_dump_file
,
555 " Hard reg %d is preferable by r%d with profit %d\n",
557 lra_reg_info
[regno
].preferred_hard_regno_profit1
);
558 if ((hard_regno
= lra_reg_info
[regno
].preferred_hard_regno2
) >= 0)
559 fprintf (lra_dump_file
,
560 " Hard reg %d is preferable by r%d with profit %d\n",
562 lra_reg_info
[regno
].preferred_hard_regno_profit2
);
566 /* Check that REGNO living through calls and setjumps, set up conflict
567 regs using LAST_CALL_USED_REG_SET, and clear corresponding bits in
568 PSEUDOS_LIVE_THROUGH_CALLS and PSEUDOS_LIVE_THROUGH_SETJUMPS. */
570 check_pseudos_live_through_calls (int regno
,
571 HARD_REG_SET last_call_used_reg_set
)
575 if (! sparseset_bit_p (pseudos_live_through_calls
, regno
))
577 sparseset_clear_bit (pseudos_live_through_calls
, regno
);
578 IOR_HARD_REG_SET (lra_reg_info
[regno
].conflict_hard_regs
,
579 last_call_used_reg_set
);
581 for (hr
= 0; hr
< FIRST_PSEUDO_REGISTER
; hr
++)
582 if (targetm
.hard_regno_call_part_clobbered (hr
,
583 PSEUDO_REGNO_MODE (regno
)))
584 add_to_hard_reg_set (&lra_reg_info
[regno
].conflict_hard_regs
,
585 PSEUDO_REGNO_MODE (regno
), hr
);
586 lra_reg_info
[regno
].call_p
= true;
587 if (! sparseset_bit_p (pseudos_live_through_setjumps
, regno
))
589 sparseset_clear_bit (pseudos_live_through_setjumps
, regno
);
590 /* Don't allocate pseudos that cross setjmps or any call, if this
591 function receives a nonlocal goto. */
592 SET_HARD_REG_SET (lra_reg_info
[regno
].conflict_hard_regs
);
595 /* Return true if insn REG is an early clobber operand in alternative
596 NALT. Negative NALT means that we don't know the current insn
597 alternative. So assume the worst. */
599 reg_early_clobber_p (const struct lra_insn_reg
*reg
, int n_alt
)
601 return (reg
->early_clobber
602 && (n_alt
== LRA_UNKNOWN_ALT
603 || (n_alt
!= LRA_NON_CLOBBERED_ALT
604 && TEST_BIT (reg
->early_clobber_alts
, n_alt
))));
607 /* Process insns of the basic block BB to update pseudo live ranges,
608 pseudo hard register conflicts, and insn notes. We do it on
609 backward scan of BB insns. CURR_POINT is the program point where
610 BB ends. The function updates this counter and returns in
611 CURR_POINT the program point where BB starts. The function also
612 does local live info updates and can delete the dead insns if
613 DEAD_INSN_P. It returns true if pseudo live info was
614 changed at the BB start. */
616 process_bb_lives (basic_block bb
, int &curr_point
, bool dead_insn_p
)
625 bool need_curr_point_incr
;
626 HARD_REG_SET last_call_used_reg_set
;
628 reg_live_out
= df_get_live_out (bb
);
629 sparseset_clear (pseudos_live
);
630 sparseset_clear (pseudos_live_through_calls
);
631 sparseset_clear (pseudos_live_through_setjumps
);
632 CLEAR_HARD_REG_SET (last_call_used_reg_set
);
633 REG_SET_TO_HARD_REG_SET (hard_regs_live
, reg_live_out
);
634 AND_COMPL_HARD_REG_SET (hard_regs_live
, eliminable_regset
);
635 EXECUTE_IF_SET_IN_BITMAP (reg_live_out
, FIRST_PSEUDO_REGISTER
, j
, bi
)
636 mark_pseudo_live (j
, curr_point
);
638 bb_gen_pseudos
= &get_bb_data (bb
)->gen_pseudos
;
639 bb_killed_pseudos
= &get_bb_data (bb
)->killed_pseudos
;
640 bitmap_clear (bb_gen_pseudos
);
641 bitmap_clear (bb_killed_pseudos
);
642 freq
= REG_FREQ_FROM_BB (bb
);
644 if (lra_dump_file
!= NULL
)
645 fprintf (lra_dump_file
, " BB %d\n", bb
->index
);
647 /* Scan the code of this basic block, noting which pseudos and hard
648 regs are born or die.
650 Note that this loop treats uninitialized values as live until the
651 beginning of the block. For example, if an instruction uses
652 (reg:DI foo), and only (subreg:SI (reg:DI foo) 0) is ever set,
653 FOO will remain live until the beginning of the block. Likewise
654 if FOO is not set at all. This is unnecessarily pessimistic, but
655 it probably doesn't matter much in practice. */
656 FOR_BB_INSNS_REVERSE_SAFE (bb
, curr_insn
, next
)
659 int n_alt
, dst_regno
, src_regno
;
661 struct lra_insn_reg
*reg
, *hr
;
663 if (!NONDEBUG_INSN_P (curr_insn
))
666 curr_id
= lra_get_insn_recog_data (curr_insn
);
667 curr_static_id
= curr_id
->insn_static_data
;
668 n_alt
= curr_id
->used_insn_alternative
;
669 if (lra_dump_file
!= NULL
)
670 fprintf (lra_dump_file
, " Insn %u: point = %d, n_alt = %d\n",
671 INSN_UID (curr_insn
), curr_point
, n_alt
);
673 set
= single_set (curr_insn
);
675 if (dead_insn_p
&& set
!= NULL_RTX
676 && REG_P (SET_DEST (set
)) && REGNO (SET_DEST (set
)) >= FIRST_PSEUDO_REGISTER
677 && find_reg_note (curr_insn
, REG_EH_REGION
, NULL_RTX
) == NULL_RTX
678 && ! may_trap_p (PATTERN (curr_insn
))
679 /* Don't do premature remove of pic offset pseudo as we can
680 start to use it after some reload generation. */
681 && (pic_offset_table_rtx
== NULL_RTX
682 || pic_offset_table_rtx
!= SET_DEST (set
)))
684 bool remove_p
= true;
686 for (reg
= curr_id
->regs
; reg
!= NULL
; reg
= reg
->next
)
687 if (reg
->type
!= OP_IN
&& sparseset_bit_p (pseudos_live
, reg
->regno
))
692 for (reg
= curr_static_id
->hard_regs
; reg
!= NULL
; reg
= reg
->next
)
693 if (reg
->type
!= OP_IN
&& !reg
->clobber_high
)
699 if (remove_p
&& ! volatile_refs_p (PATTERN (curr_insn
)))
701 dst_regno
= REGNO (SET_DEST (set
));
702 if (lra_dump_file
!= NULL
)
703 fprintf (lra_dump_file
, " Deleting dead insn %u\n",
704 INSN_UID (curr_insn
));
705 lra_set_insn_deleted (curr_insn
);
706 if (lra_reg_info
[dst_regno
].nrefs
== 0)
708 /* There might be some debug insns with the pseudo. */
712 bitmap_copy (&temp_bitmap
, &lra_reg_info
[dst_regno
].insn_bitmap
);
713 EXECUTE_IF_SET_IN_BITMAP (&temp_bitmap
, 0, uid
, bi
)
715 insn
= lra_insn_recog_data
[uid
]->insn
;
716 lra_substitute_pseudo_within_insn (insn
, dst_regno
,
717 SET_SRC (set
), true);
718 lra_update_insn_regno_info (insn
);
725 /* Update max ref width and hard reg usage. */
726 for (reg
= curr_id
->regs
; reg
!= NULL
; reg
= reg
->next
)
728 int i
, regno
= reg
->regno
;
730 if (partial_subreg_p (lra_reg_info
[regno
].biggest_mode
,
732 lra_reg_info
[regno
].biggest_mode
= reg
->biggest_mode
;
733 if (regno
< FIRST_PSEUDO_REGISTER
)
735 lra_hard_reg_usage
[regno
] += freq
;
736 /* A hard register explicitly can be used in small mode,
737 but implicitly it can be used in natural mode as a
738 part of multi-register group. Process this case
740 for (i
= 1; i
< hard_regno_nregs (regno
, reg
->biggest_mode
); i
++)
741 if (partial_subreg_p (lra_reg_info
[regno
+ i
].biggest_mode
,
742 GET_MODE (regno_reg_rtx
[regno
+ i
])))
743 lra_reg_info
[regno
+ i
].biggest_mode
744 = GET_MODE (regno_reg_rtx
[regno
+ i
]);
748 call_p
= CALL_P (curr_insn
);
749 src_regno
= (set
!= NULL_RTX
&& REG_P (SET_SRC (set
))
750 ? REGNO (SET_SRC (set
)) : -1);
751 dst_regno
= (set
!= NULL_RTX
&& REG_P (SET_DEST (set
))
752 ? REGNO (SET_DEST (set
)) : -1);
754 && src_regno
>= 0 && dst_regno
>= 0
755 /* Check that source regno does not conflict with
756 destination regno to exclude most impossible
758 && (((src_regno
>= FIRST_PSEUDO_REGISTER
759 && (! sparseset_bit_p (pseudos_live
, src_regno
)
760 || (dst_regno
>= FIRST_PSEUDO_REGISTER
761 && lra_reg_val_equal_p (src_regno
,
762 lra_reg_info
[dst_regno
].val
,
763 lra_reg_info
[dst_regno
].offset
))))
764 || (src_regno
< FIRST_PSEUDO_REGISTER
765 && ! TEST_HARD_REG_BIT (hard_regs_live
, src_regno
)))
766 /* It might be 'inheritance pseudo <- reload pseudo'. */
767 || (src_regno
>= lra_constraint_new_regno_start
768 && dst_regno
>= lra_constraint_new_regno_start
769 /* Remember to skip special cases where src/dest regnos are
770 the same, e.g. insn SET pattern has matching constraints
772 && src_regno
!= dst_regno
)))
774 int hard_regno
= -1, regno
= -1;
776 if (dst_regno
>= lra_constraint_new_regno_start
777 && src_regno
>= lra_constraint_new_regno_start
)
779 /* It might be still an original (non-reload) insn with
780 one unused output and a constraint requiring to use
781 the same reg for input/output operands. In this case
782 dst_regno and src_regno have the same value, we don't
783 need a misleading copy for this case. */
784 if (dst_regno
!= src_regno
)
785 lra_create_copy (dst_regno
, src_regno
, freq
);
787 else if (dst_regno
>= lra_constraint_new_regno_start
)
789 if ((hard_regno
= src_regno
) >= FIRST_PSEUDO_REGISTER
)
790 hard_regno
= reg_renumber
[src_regno
];
793 else if (src_regno
>= lra_constraint_new_regno_start
)
795 if ((hard_regno
= dst_regno
) >= FIRST_PSEUDO_REGISTER
)
796 hard_regno
= reg_renumber
[dst_regno
];
799 if (regno
>= 0 && hard_regno
>= 0)
800 lra_setup_reload_pseudo_preferenced_hard_reg
801 (regno
, hard_regno
, freq
);
804 sparseset_clear (start_living
);
806 /* Try to avoid unnecessary program point increments, this saves
807 a lot of time in remove_some_program_points_and_update_live_ranges.
808 We only need an increment if something becomes live or dies at this
810 need_curr_point_incr
= false;
812 /* Mark each defined value as live. We need to do this for
813 unused values because they still conflict with quantities
814 that are live at the time of the definition. */
815 for (reg
= curr_id
->regs
; reg
!= NULL
; reg
= reg
->next
)
817 if (reg
->type
!= OP_IN
)
820 |= mark_regno_live (reg
->regno
, reg
->biggest_mode
,
822 check_pseudos_live_through_calls (reg
->regno
,
823 last_call_used_reg_set
);
826 if (reg
->regno
>= FIRST_PSEUDO_REGISTER
)
827 for (hr
= curr_static_id
->hard_regs
; hr
!= NULL
; hr
= hr
->next
)
829 && maybe_gt (GET_MODE_SIZE (PSEUDO_REGNO_MODE (reg
->regno
)),
830 GET_MODE_SIZE (hr
->biggest_mode
)))
831 SET_HARD_REG_BIT (lra_reg_info
[reg
->regno
].conflict_hard_regs
,
835 for (reg
= curr_static_id
->hard_regs
; reg
!= NULL
; reg
= reg
->next
)
836 if (reg
->type
!= OP_IN
)
837 make_hard_regno_born (reg
->regno
, false);
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_born (regno
- FIRST_PSEUDO_REGISTER
, false);
845 sparseset_copy (unused_set
, start_living
);
847 sparseset_clear (start_dying
);
849 /* See which defined values die here. */
850 for (reg
= curr_id
->regs
; reg
!= NULL
; reg
= reg
->next
)
851 if (reg
->type
== OP_OUT
852 && ! reg_early_clobber_p (reg
, n_alt
) && ! reg
->subreg_p
)
854 |= mark_regno_dead (reg
->regno
, reg
->biggest_mode
,
857 for (reg
= curr_static_id
->hard_regs
; reg
!= NULL
; reg
= reg
->next
)
858 if (reg
->type
== OP_OUT
859 && ! reg_early_clobber_p (reg
, n_alt
) && ! reg
->subreg_p
)
860 make_hard_regno_dead (reg
->regno
);
862 if (curr_id
->arg_hard_regs
!= NULL
)
863 for (i
= 0; (regno
= curr_id
->arg_hard_regs
[i
]) >= 0; i
++)
864 if (regno
>= FIRST_PSEUDO_REGISTER
)
865 /* It is a clobber. */
866 make_hard_regno_dead (regno
- FIRST_PSEUDO_REGISTER
);
871 COPY_HARD_REG_SET(last_call_used_reg_set
, call_used_reg_set
);
874 HARD_REG_SET this_call_used_reg_set
;
875 get_call_reg_set_usage (curr_insn
, &this_call_used_reg_set
,
878 bool flush
= (! hard_reg_set_empty_p (last_call_used_reg_set
)
879 && ! hard_reg_set_equal_p (last_call_used_reg_set
,
880 this_call_used_reg_set
));
882 EXECUTE_IF_SET_IN_SPARSESET (pseudos_live
, j
)
884 IOR_HARD_REG_SET (lra_reg_info
[j
].actual_call_used_reg_set
,
885 this_call_used_reg_set
);
887 check_pseudos_live_through_calls
888 (j
, last_call_used_reg_set
);
890 COPY_HARD_REG_SET(last_call_used_reg_set
, this_call_used_reg_set
);
893 sparseset_ior (pseudos_live_through_calls
,
894 pseudos_live_through_calls
, pseudos_live
);
895 if (cfun
->has_nonlocal_label
896 || find_reg_note (curr_insn
, REG_SETJMP
,
897 NULL_RTX
) != NULL_RTX
)
898 sparseset_ior (pseudos_live_through_setjumps
,
899 pseudos_live_through_setjumps
, pseudos_live
);
902 /* Increment the current program point if we must. */
903 if (need_curr_point_incr
)
904 next_program_point (curr_point
, freq
);
906 sparseset_clear (start_living
);
908 need_curr_point_incr
= false;
910 /* Mark each used value as live. */
911 for (reg
= curr_id
->regs
; reg
!= NULL
; reg
= reg
->next
)
912 if (reg
->type
== OP_IN
)
915 |= mark_regno_live (reg
->regno
, reg
->biggest_mode
,
917 check_pseudos_live_through_calls (reg
->regno
,
918 last_call_used_reg_set
);
921 for (reg
= curr_static_id
->hard_regs
; reg
!= NULL
; reg
= reg
->next
)
922 if (reg
->type
== OP_IN
)
923 make_hard_regno_born (reg
->regno
, false);
925 if (curr_id
->arg_hard_regs
!= NULL
)
926 /* Make argument hard registers live. Don't create conflict
927 of used REAL_PIC_OFFSET_TABLE_REGNUM and the pic pseudo. */
928 for (i
= 0; (regno
= curr_id
->arg_hard_regs
[i
]) >= 0; i
++)
929 if (regno
< FIRST_PSEUDO_REGISTER
)
930 make_hard_regno_born (regno
, true);
932 sparseset_and_compl (dead_set
, start_living
, start_dying
);
934 /* Mark early clobber outputs dead. */
935 for (reg
= curr_id
->regs
; reg
!= NULL
; reg
= reg
->next
)
936 if (reg
->type
== OP_OUT
937 && reg_early_clobber_p (reg
, n_alt
) && ! reg
->subreg_p
)
939 |= mark_regno_dead (reg
->regno
, reg
->biggest_mode
,
942 for (reg
= curr_static_id
->hard_regs
; reg
!= NULL
; reg
= reg
->next
)
943 if (reg
->type
== OP_OUT
944 && reg_early_clobber_p (reg
, n_alt
) && ! reg
->subreg_p
)
946 struct lra_insn_reg
*reg2
;
948 /* We can have early clobbered non-operand hard reg and
949 the same hard reg as an insn input. Don't make hard
950 reg dead before the insns. */
951 for (reg2
= curr_id
->regs
; reg2
!= NULL
; reg2
= reg2
->next
)
952 if (reg2
->type
!= OP_OUT
&& reg2
->regno
== reg
->regno
)
955 make_hard_regno_dead (reg
->regno
);
958 if (need_curr_point_incr
)
959 next_program_point (curr_point
, freq
);
962 for (link_loc
= ®_NOTES (curr_insn
); (link
= *link_loc
) != NULL_RTX
;)
964 if (REG_NOTE_KIND (link
) != REG_DEAD
965 && REG_NOTE_KIND (link
) != REG_UNUSED
)
967 else if (REG_P (XEXP (link
, 0)))
969 regno
= REGNO (XEXP (link
, 0));
970 if ((REG_NOTE_KIND (link
) == REG_DEAD
971 && ! sparseset_bit_p (dead_set
, regno
))
972 || (REG_NOTE_KIND (link
) == REG_UNUSED
973 && ! sparseset_bit_p (unused_set
, regno
)))
975 *link_loc
= XEXP (link
, 1);
978 if (REG_NOTE_KIND (link
) == REG_DEAD
)
979 sparseset_clear_bit (dead_set
, regno
);
980 else if (REG_NOTE_KIND (link
) == REG_UNUSED
)
981 sparseset_clear_bit (unused_set
, regno
);
983 link_loc
= &XEXP (link
, 1);
985 EXECUTE_IF_SET_IN_SPARSESET (dead_set
, j
)
986 add_reg_note (curr_insn
, REG_DEAD
, regno_reg_rtx
[j
]);
987 EXECUTE_IF_SET_IN_SPARSESET (unused_set
, j
)
988 add_reg_note (curr_insn
, REG_UNUSED
, regno_reg_rtx
[j
]);
991 if (bb_has_eh_pred (bb
))
994 unsigned int regno
= EH_RETURN_DATA_REGNO (j
);
996 if (regno
== INVALID_REGNUM
)
998 make_hard_regno_born (regno
, false);
1001 /* Pseudos can't go in stack regs at the start of a basic block that
1002 is reached by an abnormal edge. Likewise for call clobbered regs,
1003 because caller-save, fixup_abnormal_edges and possibly the table
1004 driven EH machinery are not quite ready to handle such pseudos
1005 live across such edges. */
1006 if (bb_has_abnormal_pred (bb
))
1009 EXECUTE_IF_SET_IN_SPARSESET (pseudos_live
, px
)
1010 lra_reg_info
[px
].no_stack_p
= true;
1011 for (px
= FIRST_STACK_REG
; px
<= LAST_STACK_REG
; px
++)
1012 make_hard_regno_born (px
, false);
1014 /* No need to record conflicts for call clobbered regs if we
1015 have nonlocal labels around, as we don't ever try to
1016 allocate such regs in this case. */
1017 if (!cfun
->has_nonlocal_label
1018 && has_abnormal_call_or_eh_pred_edge_p (bb
))
1019 for (px
= 0; px
< FIRST_PSEUDO_REGISTER
; px
++)
1020 if (call_used_regs
[px
]
1021 #ifdef REAL_PIC_OFFSET_TABLE_REGNUM
1022 /* We should create a conflict of PIC pseudo with PIC
1023 hard reg as PIC hard reg can have a wrong value after
1024 jump described by the abnormal edge. In this case we
1025 can not allocate PIC hard reg to PIC pseudo as PIC
1026 pseudo will also have a wrong value. */
1027 || (px
== REAL_PIC_OFFSET_TABLE_REGNUM
1028 && pic_offset_table_rtx
!= NULL_RTX
1029 && REGNO (pic_offset_table_rtx
) >= FIRST_PSEUDO_REGISTER
)
1032 make_hard_regno_born (px
, false);
1035 bool live_change_p
= false;
1036 /* Check if bb border live info was changed. */
1037 unsigned int live_pseudos_num
= 0;
1038 EXECUTE_IF_SET_IN_BITMAP (df_get_live_in (bb
),
1039 FIRST_PSEUDO_REGISTER
, j
, bi
)
1042 if (! sparseset_bit_p (pseudos_live
, j
))
1044 live_change_p
= true;
1045 if (lra_dump_file
!= NULL
)
1046 fprintf (lra_dump_file
,
1047 " r%d is removed as live at bb%d start\n", j
, bb
->index
);
1052 && sparseset_cardinality (pseudos_live
) != live_pseudos_num
)
1054 live_change_p
= true;
1055 if (lra_dump_file
!= NULL
)
1056 EXECUTE_IF_SET_IN_SPARSESET (pseudos_live
, j
)
1057 if (! bitmap_bit_p (df_get_live_in (bb
), j
))
1058 fprintf (lra_dump_file
,
1059 " r%d is added to live at bb%d start\n", j
, bb
->index
);
1061 /* See if we'll need an increment at the end of this basic block.
1062 An increment is needed if the PSEUDOS_LIVE set is not empty,
1063 to make sure the finish points are set up correctly. */
1064 need_curr_point_incr
= (sparseset_cardinality (pseudos_live
) > 0);
1066 EXECUTE_IF_SET_IN_SPARSESET (pseudos_live
, i
)
1067 mark_pseudo_dead (i
, curr_point
);
1069 EXECUTE_IF_SET_IN_BITMAP (df_get_live_in (bb
), FIRST_PSEUDO_REGISTER
, j
, bi
)
1071 if (sparseset_cardinality (pseudos_live_through_calls
) == 0)
1073 if (sparseset_bit_p (pseudos_live_through_calls
, j
))
1074 check_pseudos_live_through_calls (j
, last_call_used_reg_set
);
1077 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; ++i
)
1079 if (!TEST_HARD_REG_BIT (hard_regs_live
, i
))
1082 if (!TEST_HARD_REG_BIT (hard_regs_spilled_into
, i
))
1085 if (bitmap_bit_p (df_get_live_in (bb
), i
))
1088 live_change_p
= true;
1090 fprintf (lra_dump_file
,
1091 " hard reg r%d is added to live at bb%d start\n", i
,
1093 bitmap_set_bit (df_get_live_in (bb
), i
);
1096 if (need_curr_point_incr
)
1097 next_program_point (curr_point
, freq
);
1099 return live_change_p
;
1102 /* Compress pseudo live ranges by removing program points where
1103 nothing happens. Complexity of many algorithms in LRA is linear
1104 function of program points number. To speed up the code we try to
1105 minimize the number of the program points here. */
1107 remove_some_program_points_and_update_live_ranges (void)
1112 lra_live_range_t r
, prev_r
, next_r
;
1113 sbitmap_iterator sbi
;
1114 bool born_p
, dead_p
, prev_born_p
, prev_dead_p
;
1116 auto_sbitmap
born (lra_live_max_point
);
1117 auto_sbitmap
dead (lra_live_max_point
);
1118 bitmap_clear (born
);
1119 bitmap_clear (dead
);
1120 max_regno
= max_reg_num ();
1121 for (i
= FIRST_PSEUDO_REGISTER
; i
< (unsigned) max_regno
; i
++)
1123 for (r
= lra_reg_info
[i
].live_ranges
; r
!= NULL
; r
= r
->next
)
1125 lra_assert (r
->start
<= r
->finish
);
1126 bitmap_set_bit (born
, r
->start
);
1127 bitmap_set_bit (dead
, r
->finish
);
1130 auto_sbitmap
born_or_dead (lra_live_max_point
);
1131 bitmap_ior (born_or_dead
, born
, dead
);
1132 map
= XCNEWVEC (int, lra_live_max_point
);
1134 prev_born_p
= prev_dead_p
= false;
1135 EXECUTE_IF_SET_IN_BITMAP (born_or_dead
, 0, i
, sbi
)
1137 born_p
= bitmap_bit_p (born
, i
);
1138 dead_p
= bitmap_bit_p (dead
, i
);
1139 if ((prev_born_p
&& ! prev_dead_p
&& born_p
&& ! dead_p
)
1140 || (prev_dead_p
&& ! prev_born_p
&& dead_p
&& ! born_p
))
1143 lra_point_freq
[n
] = MAX (lra_point_freq
[n
], lra_point_freq
[i
]);
1148 lra_point_freq
[n
] = lra_point_freq
[i
];
1150 prev_born_p
= born_p
;
1151 prev_dead_p
= dead_p
;
1154 if (lra_dump_file
!= NULL
)
1155 fprintf (lra_dump_file
, "Compressing live ranges: from %d to %d - %d%%\n",
1156 lra_live_max_point
, n
,
1157 lra_live_max_point
? 100 * n
/ lra_live_max_point
: 100);
1158 if (n
< lra_live_max_point
)
1160 lra_live_max_point
= n
;
1161 for (i
= FIRST_PSEUDO_REGISTER
; i
< (unsigned) max_regno
; i
++)
1163 for (prev_r
= NULL
, r
= lra_reg_info
[i
].live_ranges
;
1168 r
->start
= map
[r
->start
];
1169 r
->finish
= map
[r
->finish
];
1170 if (prev_r
== NULL
|| prev_r
->start
> r
->finish
+ 1)
1175 prev_r
->start
= r
->start
;
1176 prev_r
->next
= next_r
;
1177 lra_live_range_pool
.remove (r
);
1184 /* Print live ranges R to file F. */
1186 lra_print_live_range_list (FILE *f
, lra_live_range_t r
)
1188 for (; r
!= NULL
; r
= r
->next
)
1189 fprintf (f
, " [%d..%d]", r
->start
, r
->finish
);
1194 debug (lra_live_range
&ref
)
1196 lra_print_live_range_list (stderr
, &ref
);
1200 debug (lra_live_range
*ptr
)
1205 fprintf (stderr
, "<nil>\n");
1208 /* Print live ranges R to stderr. */
1210 lra_debug_live_range_list (lra_live_range_t r
)
1212 lra_print_live_range_list (stderr
, r
);
1215 /* Print live ranges of pseudo REGNO to file F. */
1217 print_pseudo_live_ranges (FILE *f
, int regno
)
1219 if (lra_reg_info
[regno
].live_ranges
== NULL
)
1221 fprintf (f
, " r%d:", regno
);
1222 lra_print_live_range_list (f
, lra_reg_info
[regno
].live_ranges
);
1225 /* Print live ranges of pseudo REGNO to stderr. */
1227 lra_debug_pseudo_live_ranges (int regno
)
1229 print_pseudo_live_ranges (stderr
, regno
);
1232 /* Print live ranges of all pseudos to file F. */
1234 print_live_ranges (FILE *f
)
1238 max_regno
= max_reg_num ();
1239 for (i
= FIRST_PSEUDO_REGISTER
; i
< max_regno
; i
++)
1240 print_pseudo_live_ranges (f
, i
);
1243 /* Print live ranges of all pseudos to stderr. */
1245 lra_debug_live_ranges (void)
1247 print_live_ranges (stderr
);
1250 /* Compress pseudo live ranges. */
1252 compress_live_ranges (void)
1254 remove_some_program_points_and_update_live_ranges ();
1255 if (lra_dump_file
!= NULL
)
1257 fprintf (lra_dump_file
, "Ranges after the compression:\n");
1258 print_live_ranges (lra_dump_file
);
1264 /* The number of the current live range pass. */
1265 int lra_live_range_iter
;
1267 /* The function creates live ranges only for memory pseudos (or for
1268 all ones if ALL_P), set up CONFLICT_HARD_REGS for the pseudos. It
1269 also does dead insn elimination if DEAD_INSN_P and global live
1270 analysis only for pseudos and only if the pseudo live info was
1271 changed on a BB border. Return TRUE if the live info was
1274 lra_create_live_ranges_1 (bool all_p
, bool dead_insn_p
)
1277 int i
, hard_regno
, max_regno
= max_reg_num ();
1279 bool bb_live_change_p
, have_referenced_pseudos
= false;
1281 timevar_push (TV_LRA_CREATE_LIVE_RANGES
);
1283 complete_info_p
= all_p
;
1284 if (lra_dump_file
!= NULL
)
1285 fprintf (lra_dump_file
,
1286 "\n********** Pseudo live ranges #%d: **********\n\n",
1287 ++lra_live_range_iter
);
1288 memset (lra_hard_reg_usage
, 0, sizeof (lra_hard_reg_usage
));
1289 for (i
= 0; i
< max_regno
; i
++)
1291 lra_reg_info
[i
].live_ranges
= NULL
;
1292 CLEAR_HARD_REG_SET (lra_reg_info
[i
].conflict_hard_regs
);
1293 lra_reg_info
[i
].preferred_hard_regno1
= -1;
1294 lra_reg_info
[i
].preferred_hard_regno2
= -1;
1295 lra_reg_info
[i
].preferred_hard_regno_profit1
= 0;
1296 lra_reg_info
[i
].preferred_hard_regno_profit2
= 0;
1298 lra_reg_info
[i
].no_stack_p
= false;
1300 /* The biggest mode is already set but its value might be to
1301 conservative because of recent transformation. Here in this
1302 file we recalculate it again as it costs practically
1304 if (i
>= FIRST_PSEUDO_REGISTER
&& regno_reg_rtx
[i
] != NULL_RTX
)
1305 lra_reg_info
[i
].biggest_mode
= GET_MODE (regno_reg_rtx
[i
]);
1307 lra_reg_info
[i
].biggest_mode
= VOIDmode
;
1308 lra_reg_info
[i
].call_p
= false;
1309 if (i
>= FIRST_PSEUDO_REGISTER
1310 && lra_reg_info
[i
].nrefs
!= 0)
1312 if ((hard_regno
= reg_renumber
[i
]) >= 0)
1313 lra_hard_reg_usage
[hard_regno
] += lra_reg_info
[i
].freq
;
1314 have_referenced_pseudos
= true;
1319 /* Under some circumstances, we can have functions without pseudo
1320 registers. For such functions, lra_live_max_point will be 0,
1321 see e.g. PR55604, and there's nothing more to do for us here. */
1322 if (! have_referenced_pseudos
)
1324 timevar_pop (TV_LRA_CREATE_LIVE_RANGES
);
1328 pseudos_live
= sparseset_alloc (max_regno
);
1329 pseudos_live_through_calls
= sparseset_alloc (max_regno
);
1330 pseudos_live_through_setjumps
= sparseset_alloc (max_regno
);
1331 start_living
= sparseset_alloc (max_regno
);
1332 start_dying
= sparseset_alloc (max_regno
);
1333 dead_set
= sparseset_alloc (max_regno
);
1334 unused_set
= sparseset_alloc (max_regno
);
1336 unsigned new_length
= get_max_uid () * 2;
1337 point_freq_vec
.truncate (0);
1338 point_freq_vec
.reserve_exact (new_length
);
1339 lra_point_freq
= point_freq_vec
.address ();
1340 auto_vec
<int, 20> post_order_rev_cfg
;
1341 inverted_post_order_compute (&post_order_rev_cfg
);
1342 lra_assert (post_order_rev_cfg
.length () == (unsigned) n_basic_blocks_for_fn (cfun
));
1343 bb_live_change_p
= false;
1344 for (i
= post_order_rev_cfg
.length () - 1; i
>= 0; --i
)
1346 bb
= BASIC_BLOCK_FOR_FN (cfun
, post_order_rev_cfg
[i
]);
1347 if (bb
== EXIT_BLOCK_PTR_FOR_FN (cfun
) || bb
1348 == ENTRY_BLOCK_PTR_FOR_FN (cfun
))
1350 if (process_bb_lives (bb
, curr_point
, dead_insn_p
))
1351 bb_live_change_p
= true;
1353 if (bb_live_change_p
)
1355 /* We need to clear pseudo live info as some pseudos can
1356 disappear, e.g. pseudos with used equivalences. */
1357 FOR_EACH_BB_FN (bb
, cfun
)
1359 bitmap_clear_range (df_get_live_in (bb
), FIRST_PSEUDO_REGISTER
,
1360 max_regno
- FIRST_PSEUDO_REGISTER
);
1361 bitmap_clear_range (df_get_live_out (bb
), FIRST_PSEUDO_REGISTER
,
1362 max_regno
- FIRST_PSEUDO_REGISTER
);
1364 /* As we did not change CFG since LRA start we can use
1365 DF-infrastructure solver to solve live data flow problem. */
1366 for (int i
= 0; i
< FIRST_PSEUDO_REGISTER
; ++i
)
1368 if (TEST_HARD_REG_BIT (hard_regs_spilled_into
, i
))
1369 bitmap_clear_bit (&all_hard_regs_bitmap
, i
);
1372 (DF_BACKWARD
, NULL
, live_con_fun_0
, live_con_fun_n
,
1373 live_trans_fun
, &all_blocks
,
1374 df_get_postorder (DF_BACKWARD
), df_get_n_blocks (DF_BACKWARD
));
1375 if (lra_dump_file
!= NULL
)
1377 fprintf (lra_dump_file
,
1378 "Global pseudo live data have been updated:\n");
1380 FOR_EACH_BB_FN (bb
, cfun
)
1382 bb_data_t bb_info
= get_bb_data (bb
);
1383 bitmap bb_livein
= df_get_live_in (bb
);
1384 bitmap bb_liveout
= df_get_live_out (bb
);
1386 fprintf (lra_dump_file
, "\nBB %d:\n", bb
->index
);
1387 lra_dump_bitmap_with_title (" gen:",
1388 &bb_info
->gen_pseudos
, bb
->index
);
1389 lra_dump_bitmap_with_title (" killed:",
1390 &bb_info
->killed_pseudos
, bb
->index
);
1391 lra_dump_bitmap_with_title (" livein:", bb_livein
, bb
->index
);
1392 lra_dump_bitmap_with_title (" liveout:", bb_liveout
, bb
->index
);
1396 lra_live_max_point
= curr_point
;
1397 if (lra_dump_file
!= NULL
)
1398 print_live_ranges (lra_dump_file
);
1400 sparseset_free (unused_set
);
1401 sparseset_free (dead_set
);
1402 sparseset_free (start_dying
);
1403 sparseset_free (start_living
);
1404 sparseset_free (pseudos_live_through_calls
);
1405 sparseset_free (pseudos_live_through_setjumps
);
1406 sparseset_free (pseudos_live
);
1407 compress_live_ranges ();
1408 timevar_pop (TV_LRA_CREATE_LIVE_RANGES
);
1409 return bb_live_change_p
;
1412 /* The main entry function creates live-ranges and other live info
1413 necessary for the assignment sub-pass. It uses
1414 lra_creates_live_ranges_1 -- so read comments for the
1417 lra_create_live_ranges (bool all_p
, bool dead_insn_p
)
1419 if (! lra_create_live_ranges_1 (all_p
, dead_insn_p
))
1421 if (lra_dump_file
!= NULL
)
1422 fprintf (lra_dump_file
, "Live info was changed -- recalculate it\n");
1423 /* Live info was changed on a bb border. It means that some info,
1424 e.g. about conflict regs, calls crossed, and live ranges may be
1425 wrong. We need this info for allocation. So recalculate it
1426 again but without removing dead insns which can change live info
1427 again. Repetitive live range calculations are expensive therefore
1428 we stop here as we already have correct info although some
1429 improvement in rare cases could be possible on this sub-pass if
1430 we do dead insn elimination again (still the improvement may
1432 lra_clear_live_ranges ();
1433 bool res
= lra_create_live_ranges_1 (all_p
, false);
1437 /* Finish all live ranges. */
1439 lra_clear_live_ranges (void)
1443 for (i
= 0; i
< max_reg_num (); i
++)
1444 free_live_range_list (lra_reg_info
[i
].live_ranges
);
1445 point_freq_vec
.release ();
1448 /* Initialize live ranges data once per function. */
1450 lra_live_ranges_init (void)
1452 bitmap_initialize (&temp_bitmap
, ®_obstack
);
1453 initiate_live_solver ();
1456 /* Finish live ranges data once per function. */
1458 lra_live_ranges_finish (void)
1460 finish_live_solver ();
1461 bitmap_clear (&temp_bitmap
);
1462 lra_live_range_pool
.release ();