1 /* Build live ranges for pseudos.
2 Copyright (C) 2010-2019 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
)
228 /* Return TRUE if set A contains a pseudo register, otherwise, return FALSE. */
230 sparseset_contains_pseudos_p (sparseset a
)
233 EXECUTE_IF_SET_IN_SPARSESET (a
, regno
)
234 if (!HARD_REGISTER_NUM_P (regno
))
239 /* Mark pseudo REGNO as living or dying at program point POINT, depending on
240 whether TYPE is a definition or a use. If this is the first reference to
241 REGNO that we've encountered, then create a new live range for it. */
244 update_pseudo_point (int regno
, int point
, enum point_type type
)
248 /* Don't compute points for hard registers. */
249 if (HARD_REGISTER_NUM_P (regno
))
252 if (complete_info_p
|| lra_get_regno_hard_regno (regno
) < 0)
254 if (type
== DEF_POINT
)
256 if (sparseset_bit_p (pseudos_live
, regno
))
258 p
= lra_reg_info
[regno
].live_ranges
;
259 lra_assert (p
!= NULL
);
265 if (!sparseset_bit_p (pseudos_live
, regno
)
266 && ((p
= lra_reg_info
[regno
].live_ranges
) == NULL
267 || (p
->finish
!= point
&& p
->finish
+ 1 != point
)))
268 lra_reg_info
[regno
].live_ranges
269 = create_live_range (regno
, point
, -1, p
);
274 /* The corresponding bitmaps of BB currently being processed. */
275 static bitmap bb_killed_pseudos
, bb_gen_pseudos
;
277 /* Record hard register REGNO as now being live. It updates
278 living hard regs and START_LIVING. */
280 make_hard_regno_live (int regno
)
282 lra_assert (HARD_REGISTER_NUM_P (regno
));
283 if (TEST_HARD_REG_BIT (hard_regs_live
, regno
))
285 SET_HARD_REG_BIT (hard_regs_live
, regno
);
286 sparseset_set_bit (start_living
, regno
);
287 if (fixed_regs
[regno
] || TEST_HARD_REG_BIT (hard_regs_spilled_into
, regno
))
288 bitmap_set_bit (bb_gen_pseudos
, regno
);
291 /* Process the definition of hard register REGNO. This updates
292 hard_regs_live, START_DYING and conflict hard regs for living
295 make_hard_regno_dead (int regno
)
297 lra_assert (HARD_REGISTER_NUM_P (regno
));
299 EXECUTE_IF_SET_IN_SPARSESET (pseudos_live
, i
)
300 SET_HARD_REG_BIT (lra_reg_info
[i
].conflict_hard_regs
, regno
);
302 if (! TEST_HARD_REG_BIT (hard_regs_live
, regno
))
304 CLEAR_HARD_REG_BIT (hard_regs_live
, regno
);
305 sparseset_set_bit (start_dying
, regno
);
306 if (fixed_regs
[regno
] || TEST_HARD_REG_BIT (hard_regs_spilled_into
, regno
))
308 bitmap_clear_bit (bb_gen_pseudos
, regno
);
309 bitmap_set_bit (bb_killed_pseudos
, regno
);
313 /* Mark pseudo REGNO as now being live and update START_LIVING. */
315 mark_pseudo_live (int regno
)
317 lra_assert (!HARD_REGISTER_NUM_P (regno
));
318 if (sparseset_bit_p (pseudos_live
, regno
))
321 sparseset_set_bit (pseudos_live
, regno
);
322 sparseset_set_bit (start_living
, regno
);
325 /* Mark pseudo REGNO as now being dead and update START_DYING. */
327 mark_pseudo_dead (int regno
)
329 lra_assert (!HARD_REGISTER_NUM_P (regno
));
330 IOR_HARD_REG_SET (lra_reg_info
[regno
].conflict_hard_regs
, hard_regs_live
);
331 if (!sparseset_bit_p (pseudos_live
, regno
))
334 sparseset_clear_bit (pseudos_live
, regno
);
335 sparseset_set_bit (start_dying
, regno
);
338 /* Mark register REGNO (pseudo or hard register) in MODE as being live
339 and update BB_GEN_PSEUDOS. */
341 mark_regno_live (int regno
, machine_mode mode
)
345 if (HARD_REGISTER_NUM_P (regno
))
347 for (last
= end_hard_regno (mode
, regno
); regno
< last
; regno
++)
348 make_hard_regno_live (regno
);
352 mark_pseudo_live (regno
);
353 bitmap_set_bit (bb_gen_pseudos
, regno
);
358 /* Mark register REGNO (pseudo or hard register) in MODE as being dead
359 and update BB_GEN_PSEUDOS and BB_KILLED_PSEUDOS. */
361 mark_regno_dead (int regno
, machine_mode mode
)
365 if (HARD_REGISTER_NUM_P (regno
))
367 for (last
= end_hard_regno (mode
, regno
); regno
< last
; regno
++)
368 make_hard_regno_dead (regno
);
372 mark_pseudo_dead (regno
);
373 bitmap_clear_bit (bb_gen_pseudos
, regno
);
374 bitmap_set_bit (bb_killed_pseudos
, regno
);
380 /* This page contains code for making global live analysis of pseudos.
381 The code works only when pseudo live info is changed on a BB
382 border. That might be a consequence of some global transformations
383 in LRA, e.g. PIC pseudo reuse or rematerialization. */
385 /* Structure describing local BB data used for pseudo
387 struct bb_data_pseudos
389 /* Basic block about which the below data are. */
391 bitmap_head killed_pseudos
; /* pseudos killed in the BB. */
392 bitmap_head gen_pseudos
; /* pseudos generated in the BB. */
395 /* Array for all BB data. Indexed by the corresponding BB index. */
396 typedef struct bb_data_pseudos
*bb_data_t
;
398 /* All basic block data are referred through the following array. */
399 static bb_data_t bb_data
;
401 /* Two small functions for access to the bb data. */
402 static inline bb_data_t
403 get_bb_data (basic_block bb
)
405 return &bb_data
[(bb
)->index
];
408 static inline bb_data_t
409 get_bb_data_by_index (int index
)
411 return &bb_data
[index
];
414 /* Bitmap with all hard regs. */
415 static bitmap_head all_hard_regs_bitmap
;
417 /* The transfer function used by the DF equation solver to propagate
418 live info through block with BB_INDEX according to the following
421 bb.livein = (bb.liveout - bb.kill) OR bb.gen
424 live_trans_fun (int bb_index
)
426 basic_block bb
= get_bb_data_by_index (bb_index
)->bb
;
427 bitmap bb_liveout
= df_get_live_out (bb
);
428 bitmap bb_livein
= df_get_live_in (bb
);
429 bb_data_t bb_info
= get_bb_data (bb
);
431 bitmap_and_compl (&temp_bitmap
, bb_liveout
, &all_hard_regs_bitmap
);
432 return bitmap_ior_and_compl (bb_livein
, &bb_info
->gen_pseudos
,
433 &temp_bitmap
, &bb_info
->killed_pseudos
);
436 /* The confluence function used by the DF equation solver to set up
437 live info for a block BB without predecessor. */
439 live_con_fun_0 (basic_block bb
)
441 bitmap_and_into (df_get_live_out (bb
), &all_hard_regs_bitmap
);
444 /* The confluence function used by the DF equation solver to propagate
445 live info from successor to predecessor on edge E according to the
448 bb.liveout = 0 for entry block | OR (livein of successors)
451 live_con_fun_n (edge e
)
453 basic_block bb
= e
->src
;
454 basic_block dest
= e
->dest
;
455 bitmap bb_liveout
= df_get_live_out (bb
);
456 bitmap dest_livein
= df_get_live_in (dest
);
458 return bitmap_ior_and_compl_into (bb_liveout
,
459 dest_livein
, &all_hard_regs_bitmap
);
462 /* Indexes of all function blocks. */
463 static bitmap_head all_blocks
;
465 /* Allocate and initialize data needed for global pseudo live
468 initiate_live_solver (void)
470 bitmap_initialize (&all_hard_regs_bitmap
, ®_obstack
);
471 bitmap_set_range (&all_hard_regs_bitmap
, 0, FIRST_PSEUDO_REGISTER
);
472 bb_data
= XNEWVEC (struct bb_data_pseudos
, last_basic_block_for_fn (cfun
));
473 bitmap_initialize (&all_blocks
, ®_obstack
);
476 FOR_ALL_BB_FN (bb
, cfun
)
478 bb_data_t bb_info
= get_bb_data (bb
);
480 bitmap_initialize (&bb_info
->killed_pseudos
, ®_obstack
);
481 bitmap_initialize (&bb_info
->gen_pseudos
, ®_obstack
);
482 bitmap_set_bit (&all_blocks
, bb
->index
);
486 /* Free all data needed for global pseudo live analysis. */
488 finish_live_solver (void)
492 bitmap_clear (&all_blocks
);
493 FOR_ALL_BB_FN (bb
, cfun
)
495 bb_data_t bb_info
= get_bb_data (bb
);
496 bitmap_clear (&bb_info
->killed_pseudos
);
497 bitmap_clear (&bb_info
->gen_pseudos
);
500 bitmap_clear (&all_hard_regs_bitmap
);
505 /* Insn currently scanned. */
506 static rtx_insn
*curr_insn
;
508 static lra_insn_recog_data_t curr_id
;
509 /* The insn static data. */
510 static struct lra_static_insn_data
*curr_static_id
;
512 /* Vec containing execution frequencies of program points. */
513 static vec
<int> point_freq_vec
;
515 /* The start of the above vector elements. */
518 /* Increment the current program point POINT to the next point which has
519 execution frequency FREQ. */
521 next_program_point (int &point
, int freq
)
523 point_freq_vec
.safe_push (freq
);
524 lra_point_freq
= point_freq_vec
.address ();
528 /* Update the preference of HARD_REGNO for pseudo REGNO by PROFIT. */
530 lra_setup_reload_pseudo_preferenced_hard_reg (int regno
,
531 int hard_regno
, int profit
)
533 lra_assert (regno
>= lra_constraint_new_regno_start
);
534 if (lra_reg_info
[regno
].preferred_hard_regno1
== hard_regno
)
535 lra_reg_info
[regno
].preferred_hard_regno_profit1
+= profit
;
536 else if (lra_reg_info
[regno
].preferred_hard_regno2
== hard_regno
)
537 lra_reg_info
[regno
].preferred_hard_regno_profit2
+= profit
;
538 else if (lra_reg_info
[regno
].preferred_hard_regno1
< 0)
540 lra_reg_info
[regno
].preferred_hard_regno1
= hard_regno
;
541 lra_reg_info
[regno
].preferred_hard_regno_profit1
= profit
;
543 else if (lra_reg_info
[regno
].preferred_hard_regno2
< 0
544 || profit
> lra_reg_info
[regno
].preferred_hard_regno_profit2
)
546 lra_reg_info
[regno
].preferred_hard_regno2
= hard_regno
;
547 lra_reg_info
[regno
].preferred_hard_regno_profit2
= profit
;
551 /* Keep the 1st hard regno as more profitable. */
552 if (lra_reg_info
[regno
].preferred_hard_regno1
>= 0
553 && lra_reg_info
[regno
].preferred_hard_regno2
>= 0
554 && (lra_reg_info
[regno
].preferred_hard_regno_profit2
555 > lra_reg_info
[regno
].preferred_hard_regno_profit1
))
557 std::swap (lra_reg_info
[regno
].preferred_hard_regno1
,
558 lra_reg_info
[regno
].preferred_hard_regno2
);
559 std::swap (lra_reg_info
[regno
].preferred_hard_regno_profit1
,
560 lra_reg_info
[regno
].preferred_hard_regno_profit2
);
562 if (lra_dump_file
!= NULL
)
564 if ((hard_regno
= lra_reg_info
[regno
].preferred_hard_regno1
) >= 0)
565 fprintf (lra_dump_file
,
566 " Hard reg %d is preferable by r%d with profit %d\n",
568 lra_reg_info
[regno
].preferred_hard_regno_profit1
);
569 if ((hard_regno
= lra_reg_info
[regno
].preferred_hard_regno2
) >= 0)
570 fprintf (lra_dump_file
,
571 " Hard reg %d is preferable by r%d with profit %d\n",
573 lra_reg_info
[regno
].preferred_hard_regno_profit2
);
577 /* Check that REGNO living through calls and setjumps, set up conflict
578 regs using LAST_CALL_USED_REG_SET, and clear corresponding bits in
579 PSEUDOS_LIVE_THROUGH_CALLS and PSEUDOS_LIVE_THROUGH_SETJUMPS.
580 CALL_INSN is a call that is representative of all calls in the region
581 described by the PSEUDOS_LIVE_THROUGH_* sets, in terms of the registers
582 that it preserves and clobbers. */
585 check_pseudos_live_through_calls (int regno
,
586 HARD_REG_SET last_call_used_reg_set
,
590 rtx_insn
*old_call_insn
;
592 if (! sparseset_bit_p (pseudos_live_through_calls
, regno
))
595 gcc_assert (call_insn
&& CALL_P (call_insn
));
596 old_call_insn
= lra_reg_info
[regno
].call_insn
;
598 || (targetm
.return_call_with_max_clobbers
599 && targetm
.return_call_with_max_clobbers (old_call_insn
, call_insn
)
601 lra_reg_info
[regno
].call_insn
= call_insn
;
603 sparseset_clear_bit (pseudos_live_through_calls
, regno
);
604 IOR_HARD_REG_SET (lra_reg_info
[regno
].conflict_hard_regs
,
605 last_call_used_reg_set
);
607 for (hr
= 0; HARD_REGISTER_NUM_P (hr
); hr
++)
608 if (targetm
.hard_regno_call_part_clobbered (call_insn
, hr
,
609 PSEUDO_REGNO_MODE (regno
)))
610 add_to_hard_reg_set (&lra_reg_info
[regno
].conflict_hard_regs
,
611 PSEUDO_REGNO_MODE (regno
), hr
);
612 if (! sparseset_bit_p (pseudos_live_through_setjumps
, regno
))
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 /* Return true if insn REG is an early clobber operand in alternative
621 NALT. Negative NALT means that we don't know the current insn
622 alternative. So assume the worst. */
624 reg_early_clobber_p (const struct lra_insn_reg
*reg
, int n_alt
)
626 return (reg
->early_clobber
627 && (n_alt
== LRA_UNKNOWN_ALT
628 || (n_alt
!= LRA_NON_CLOBBERED_ALT
629 && TEST_BIT (reg
->early_clobber_alts
, n_alt
))));
632 /* Return true if call instructions CALL1 and CALL2 use ABIs that
633 preserve the same set of registers. */
636 calls_have_same_clobbers_p (rtx_insn
*call1
, rtx_insn
*call2
)
638 if (!targetm
.return_call_with_max_clobbers
)
641 return (targetm
.return_call_with_max_clobbers (call1
, call2
) == call1
642 && targetm
.return_call_with_max_clobbers (call2
, call1
) == call2
);
645 /* Process insns of the basic block BB to update pseudo live ranges,
646 pseudo hard register conflicts, and insn notes. We do it on
647 backward scan of BB insns. CURR_POINT is the program point where
648 BB ends. The function updates this counter and returns in
649 CURR_POINT the program point where BB starts. The function also
650 does local live info updates and can delete the dead insns if
651 DEAD_INSN_P. It returns true if pseudo live info was
652 changed at the BB start. */
654 process_bb_lives (basic_block bb
, int &curr_point
, bool dead_insn_p
)
663 bool need_curr_point_incr
;
664 HARD_REG_SET last_call_used_reg_set
;
665 rtx_insn
*call_insn
= NULL
;
666 rtx_insn
*last_call_insn
= NULL
;
668 reg_live_out
= df_get_live_out (bb
);
669 sparseset_clear (pseudos_live
);
670 sparseset_clear (pseudos_live_through_calls
);
671 sparseset_clear (pseudos_live_through_setjumps
);
672 CLEAR_HARD_REG_SET (last_call_used_reg_set
);
673 REG_SET_TO_HARD_REG_SET (hard_regs_live
, reg_live_out
);
674 AND_COMPL_HARD_REG_SET (hard_regs_live
, eliminable_regset
);
675 EXECUTE_IF_SET_IN_BITMAP (reg_live_out
, FIRST_PSEUDO_REGISTER
, j
, bi
)
677 update_pseudo_point (j
, curr_point
, USE_POINT
);
678 mark_pseudo_live (j
);
681 bb_gen_pseudos
= &get_bb_data (bb
)->gen_pseudos
;
682 bb_killed_pseudos
= &get_bb_data (bb
)->killed_pseudos
;
683 bitmap_clear (bb_gen_pseudos
);
684 bitmap_clear (bb_killed_pseudos
);
685 freq
= REG_FREQ_FROM_BB (bb
);
687 if (lra_dump_file
!= NULL
)
688 fprintf (lra_dump_file
, " BB %d\n", bb
->index
);
690 /* Scan the code of this basic block, noting which pseudos and hard
691 regs are born or die.
693 Note that this loop treats uninitialized values as live until the
694 beginning of the block. For example, if an instruction uses
695 (reg:DI foo), and only (subreg:SI (reg:DI foo) 0) is ever set,
696 FOO will remain live until the beginning of the block. Likewise
697 if FOO is not set at all. This is unnecessarily pessimistic, but
698 it probably doesn't matter much in practice. */
699 FOR_BB_INSNS_REVERSE_SAFE (bb
, curr_insn
, next
)
702 int n_alt
, dst_regno
, src_regno
;
704 struct lra_insn_reg
*reg
, *hr
;
706 if (!NONDEBUG_INSN_P (curr_insn
))
709 curr_id
= lra_get_insn_recog_data (curr_insn
);
710 curr_static_id
= curr_id
->insn_static_data
;
711 n_alt
= curr_id
->used_insn_alternative
;
712 if (lra_dump_file
!= NULL
)
713 fprintf (lra_dump_file
, " Insn %u: point = %d, n_alt = %d\n",
714 INSN_UID (curr_insn
), curr_point
, n_alt
);
716 set
= single_set (curr_insn
);
718 if (dead_insn_p
&& set
!= NULL_RTX
719 && REG_P (SET_DEST (set
)) && !HARD_REGISTER_P (SET_DEST (set
))
720 && find_reg_note (curr_insn
, REG_EH_REGION
, NULL_RTX
) == NULL_RTX
721 && ! may_trap_p (PATTERN (curr_insn
))
722 /* Don't do premature remove of pic offset pseudo as we can
723 start to use it after some reload generation. */
724 && (pic_offset_table_rtx
== NULL_RTX
725 || pic_offset_table_rtx
!= SET_DEST (set
)))
727 bool remove_p
= true;
729 for (reg
= curr_id
->regs
; reg
!= NULL
; reg
= reg
->next
)
730 if (reg
->type
!= OP_IN
&& sparseset_bit_p (pseudos_live
, reg
->regno
))
735 for (reg
= curr_static_id
->hard_regs
; reg
!= NULL
; reg
= reg
->next
)
736 if (reg
->type
!= OP_IN
&& !reg
->clobber_high
)
742 if (remove_p
&& ! volatile_refs_p (PATTERN (curr_insn
)))
744 dst_regno
= REGNO (SET_DEST (set
));
745 if (lra_dump_file
!= NULL
)
746 fprintf (lra_dump_file
, " Deleting dead insn %u\n",
747 INSN_UID (curr_insn
));
748 lra_set_insn_deleted (curr_insn
);
749 if (lra_reg_info
[dst_regno
].nrefs
== 0)
751 /* There might be some debug insns with the pseudo. */
755 bitmap_copy (&temp_bitmap
, &lra_reg_info
[dst_regno
].insn_bitmap
);
756 EXECUTE_IF_SET_IN_BITMAP (&temp_bitmap
, 0, uid
, bi
)
758 insn
= lra_insn_recog_data
[uid
]->insn
;
759 lra_substitute_pseudo_within_insn (insn
, dst_regno
,
760 SET_SRC (set
), true);
761 lra_update_insn_regno_info (insn
);
768 /* Update max ref width and hard reg usage. */
769 for (reg
= curr_id
->regs
; reg
!= NULL
; reg
= reg
->next
)
771 int i
, regno
= reg
->regno
;
773 if (partial_subreg_p (lra_reg_info
[regno
].biggest_mode
,
775 lra_reg_info
[regno
].biggest_mode
= reg
->biggest_mode
;
776 if (HARD_REGISTER_NUM_P (regno
))
778 lra_hard_reg_usage
[regno
] += freq
;
779 /* A hard register explicitly can be used in small mode,
780 but implicitly it can be used in natural mode as a
781 part of multi-register group. Process this case
783 for (i
= 1; i
< hard_regno_nregs (regno
, reg
->biggest_mode
); i
++)
784 if (partial_subreg_p (lra_reg_info
[regno
+ i
].biggest_mode
,
785 GET_MODE (regno_reg_rtx
[regno
+ i
])))
786 lra_reg_info
[regno
+ i
].biggest_mode
787 = GET_MODE (regno_reg_rtx
[regno
+ i
]);
791 call_p
= CALL_P (curr_insn
);
793 /* If we have a simple register copy and the source reg is live after
794 this instruction, then remove the source reg from the live set so
795 that it will not conflict with the destination reg. */
796 rtx ignore_reg
= non_conflicting_reg_copy_p (curr_insn
);
797 if (ignore_reg
!= NULL_RTX
)
799 int ignore_regno
= REGNO (ignore_reg
);
800 if (HARD_REGISTER_NUM_P (ignore_regno
)
801 && TEST_HARD_REG_BIT (hard_regs_live
, ignore_regno
))
802 CLEAR_HARD_REG_BIT (hard_regs_live
, ignore_regno
);
803 else if (!HARD_REGISTER_NUM_P (ignore_regno
)
804 && sparseset_bit_p (pseudos_live
, ignore_regno
))
805 sparseset_clear_bit (pseudos_live
, ignore_regno
);
807 /* We don't need any special handling of the source reg if
808 it is dead after this instruction. */
809 ignore_reg
= NULL_RTX
;
812 src_regno
= (set
!= NULL_RTX
&& REG_P (SET_SRC (set
))
813 ? REGNO (SET_SRC (set
)) : -1);
814 dst_regno
= (set
!= NULL_RTX
&& REG_P (SET_DEST (set
))
815 ? REGNO (SET_DEST (set
)) : -1);
817 && src_regno
>= 0 && dst_regno
>= 0
818 /* Check that source regno does not conflict with
819 destination regno to exclude most impossible
821 && (((!HARD_REGISTER_NUM_P (src_regno
)
822 && (! sparseset_bit_p (pseudos_live
, src_regno
)
823 || (!HARD_REGISTER_NUM_P (dst_regno
)
824 && lra_reg_val_equal_p (src_regno
,
825 lra_reg_info
[dst_regno
].val
,
826 lra_reg_info
[dst_regno
].offset
))))
827 || (HARD_REGISTER_NUM_P (src_regno
)
828 && ! TEST_HARD_REG_BIT (hard_regs_live
, src_regno
)))
829 /* It might be 'inheritance pseudo <- reload pseudo'. */
830 || (src_regno
>= lra_constraint_new_regno_start
831 && dst_regno
>= lra_constraint_new_regno_start
832 /* Remember to skip special cases where src/dest regnos are
833 the same, e.g. insn SET pattern has matching constraints
835 && src_regno
!= dst_regno
)))
837 int hard_regno
= -1, regno
= -1;
839 if (dst_regno
>= lra_constraint_new_regno_start
840 && src_regno
>= lra_constraint_new_regno_start
)
842 /* It might be still an original (non-reload) insn with
843 one unused output and a constraint requiring to use
844 the same reg for input/output operands. In this case
845 dst_regno and src_regno have the same value, we don't
846 need a misleading copy for this case. */
847 if (dst_regno
!= src_regno
)
848 lra_create_copy (dst_regno
, src_regno
, freq
);
850 else if (dst_regno
>= lra_constraint_new_regno_start
)
852 if (!HARD_REGISTER_NUM_P (hard_regno
= src_regno
))
853 hard_regno
= reg_renumber
[src_regno
];
856 else if (src_regno
>= lra_constraint_new_regno_start
)
858 if (!HARD_REGISTER_NUM_P (hard_regno
= dst_regno
))
859 hard_regno
= reg_renumber
[dst_regno
];
862 if (regno
>= 0 && hard_regno
>= 0)
863 lra_setup_reload_pseudo_preferenced_hard_reg
864 (regno
, hard_regno
, freq
);
867 sparseset_clear (start_living
);
869 /* Mark each defined value as live. We need to do this for
870 unused values because they still conflict with quantities
871 that are live at the time of the definition. */
872 for (reg
= curr_id
->regs
; reg
!= NULL
; reg
= reg
->next
)
874 if (reg
->type
!= OP_IN
)
876 update_pseudo_point (reg
->regno
, curr_point
, USE_POINT
);
877 mark_regno_live (reg
->regno
, reg
->biggest_mode
);
878 check_pseudos_live_through_calls (reg
->regno
,
879 last_call_used_reg_set
,
883 if (!HARD_REGISTER_NUM_P (reg
->regno
))
884 for (hr
= curr_static_id
->hard_regs
; hr
!= NULL
; hr
= hr
->next
)
886 && maybe_gt (GET_MODE_SIZE (PSEUDO_REGNO_MODE (reg
->regno
)),
887 GET_MODE_SIZE (hr
->biggest_mode
)))
888 SET_HARD_REG_BIT (lra_reg_info
[reg
->regno
].conflict_hard_regs
,
892 for (reg
= curr_static_id
->hard_regs
; reg
!= NULL
; reg
= reg
->next
)
893 if (reg
->type
!= OP_IN
)
894 make_hard_regno_live (reg
->regno
);
896 if (curr_id
->arg_hard_regs
!= NULL
)
897 for (i
= 0; (regno
= curr_id
->arg_hard_regs
[i
]) >= 0; i
++)
898 if (!HARD_REGISTER_NUM_P (regno
))
899 /* It is a clobber. */
900 make_hard_regno_live (regno
- FIRST_PSEUDO_REGISTER
);
902 sparseset_copy (unused_set
, start_living
);
904 sparseset_clear (start_dying
);
906 /* See which defined values die here. */
907 for (reg
= curr_id
->regs
; reg
!= NULL
; reg
= reg
->next
)
908 if (reg
->type
!= OP_IN
909 && ! reg_early_clobber_p (reg
, n_alt
) && ! reg
->subreg_p
)
911 if (reg
->type
== OP_OUT
)
912 update_pseudo_point (reg
->regno
, curr_point
, DEF_POINT
);
913 mark_regno_dead (reg
->regno
, reg
->biggest_mode
);
916 for (reg
= curr_static_id
->hard_regs
; reg
!= NULL
; reg
= reg
->next
)
917 if (reg
->type
!= OP_IN
918 && ! reg_early_clobber_p (reg
, n_alt
) && ! reg
->subreg_p
)
919 make_hard_regno_dead (reg
->regno
);
921 if (curr_id
->arg_hard_regs
!= NULL
)
922 for (i
= 0; (regno
= curr_id
->arg_hard_regs
[i
]) >= 0; i
++)
923 if (!HARD_REGISTER_NUM_P (regno
))
924 /* It is a clobber. */
925 make_hard_regno_dead (regno
- FIRST_PSEUDO_REGISTER
);
929 call_insn
= curr_insn
;
930 if (! flag_ipa_ra
&& ! targetm
.return_call_with_max_clobbers
)
931 COPY_HARD_REG_SET(last_call_used_reg_set
, call_used_reg_set
);
934 HARD_REG_SET this_call_used_reg_set
;
935 get_call_reg_set_usage (curr_insn
, &this_call_used_reg_set
,
938 bool flush
= (! hard_reg_set_empty_p (last_call_used_reg_set
)
939 && ( ! hard_reg_set_equal_p (last_call_used_reg_set
,
940 this_call_used_reg_set
)))
941 || (last_call_insn
&& ! calls_have_same_clobbers_p
945 EXECUTE_IF_SET_IN_SPARSESET (pseudos_live
, j
)
947 IOR_HARD_REG_SET (lra_reg_info
[j
].actual_call_used_reg_set
,
948 this_call_used_reg_set
);
951 check_pseudos_live_through_calls (j
,
952 last_call_used_reg_set
,
955 COPY_HARD_REG_SET(last_call_used_reg_set
, this_call_used_reg_set
);
956 last_call_insn
= call_insn
;
959 sparseset_ior (pseudos_live_through_calls
,
960 pseudos_live_through_calls
, pseudos_live
);
961 if (cfun
->has_nonlocal_label
962 || (!targetm
.setjmp_preserves_nonvolatile_regs_p ()
963 && (find_reg_note (curr_insn
, REG_SETJMP
, NULL_RTX
)
965 sparseset_ior (pseudos_live_through_setjumps
,
966 pseudos_live_through_setjumps
, pseudos_live
);
969 /* Increment the current program point if we must. */
970 if (sparseset_contains_pseudos_p (unused_set
)
971 || sparseset_contains_pseudos_p (start_dying
))
972 next_program_point (curr_point
, freq
);
974 /* If we removed the source reg from a simple register copy from the
975 live set above, then add it back now so we don't accidentally add
976 it to the start_living set below. */
977 if (ignore_reg
!= NULL_RTX
)
979 int ignore_regno
= REGNO (ignore_reg
);
980 if (HARD_REGISTER_NUM_P (ignore_regno
))
981 SET_HARD_REG_BIT (hard_regs_live
, ignore_regno
);
983 sparseset_set_bit (pseudos_live
, ignore_regno
);
986 sparseset_clear (start_living
);
988 /* Mark each used value as live. */
989 for (reg
= curr_id
->regs
; reg
!= NULL
; reg
= reg
->next
)
990 if (reg
->type
!= OP_OUT
)
992 if (reg
->type
== OP_IN
)
993 update_pseudo_point (reg
->regno
, curr_point
, USE_POINT
);
994 mark_regno_live (reg
->regno
, reg
->biggest_mode
);
995 check_pseudos_live_through_calls (reg
->regno
,
996 last_call_used_reg_set
,
1000 for (reg
= curr_static_id
->hard_regs
; reg
!= NULL
; reg
= reg
->next
)
1001 if (reg
->type
!= OP_OUT
)
1002 make_hard_regno_live (reg
->regno
);
1004 if (curr_id
->arg_hard_regs
!= NULL
)
1005 /* Make argument hard registers live. */
1006 for (i
= 0; (regno
= curr_id
->arg_hard_regs
[i
]) >= 0; i
++)
1007 if (HARD_REGISTER_NUM_P (regno
))
1008 make_hard_regno_live (regno
);
1010 sparseset_and_compl (dead_set
, start_living
, start_dying
);
1012 sparseset_clear (start_dying
);
1014 /* Mark early clobber outputs dead. */
1015 for (reg
= curr_id
->regs
; reg
!= NULL
; reg
= reg
->next
)
1016 if (reg
->type
!= OP_IN
1017 && reg_early_clobber_p (reg
, n_alt
) && ! reg
->subreg_p
)
1019 if (reg
->type
== OP_OUT
)
1020 update_pseudo_point (reg
->regno
, curr_point
, DEF_POINT
);
1021 mark_regno_dead (reg
->regno
, reg
->biggest_mode
);
1023 /* We're done processing inputs, so make sure early clobber
1024 operands that are both inputs and outputs are still live. */
1025 if (reg
->type
== OP_INOUT
)
1026 mark_regno_live (reg
->regno
, reg
->biggest_mode
);
1029 for (reg
= curr_static_id
->hard_regs
; reg
!= NULL
; reg
= reg
->next
)
1030 if (reg
->type
!= OP_IN
1031 && reg_early_clobber_p (reg
, n_alt
) && ! reg
->subreg_p
)
1033 struct lra_insn_reg
*reg2
;
1035 /* We can have early clobbered non-operand hard reg and
1036 the same hard reg as an insn input. Don't make hard
1037 reg dead before the insns. */
1038 for (reg2
= curr_id
->regs
; reg2
!= NULL
; reg2
= reg2
->next
)
1039 if (reg2
->type
!= OP_OUT
&& reg2
->regno
== reg
->regno
)
1042 make_hard_regno_dead (reg
->regno
);
1045 /* Increment the current program point if we must. */
1046 if (sparseset_contains_pseudos_p (dead_set
)
1047 || sparseset_contains_pseudos_p (start_dying
))
1048 next_program_point (curr_point
, freq
);
1051 for (link_loc
= ®_NOTES (curr_insn
); (link
= *link_loc
) != NULL_RTX
;)
1053 if (REG_NOTE_KIND (link
) != REG_DEAD
1054 && REG_NOTE_KIND (link
) != REG_UNUSED
)
1056 else if (REG_P (XEXP (link
, 0)))
1058 regno
= REGNO (XEXP (link
, 0));
1059 if ((REG_NOTE_KIND (link
) == REG_DEAD
1060 && ! sparseset_bit_p (dead_set
, regno
))
1061 || (REG_NOTE_KIND (link
) == REG_UNUSED
1062 && ! sparseset_bit_p (unused_set
, regno
)))
1064 *link_loc
= XEXP (link
, 1);
1067 if (REG_NOTE_KIND (link
) == REG_DEAD
)
1068 sparseset_clear_bit (dead_set
, regno
);
1069 else if (REG_NOTE_KIND (link
) == REG_UNUSED
)
1070 sparseset_clear_bit (unused_set
, regno
);
1072 link_loc
= &XEXP (link
, 1);
1074 EXECUTE_IF_SET_IN_SPARSESET (dead_set
, j
)
1075 add_reg_note (curr_insn
, REG_DEAD
, regno_reg_rtx
[j
]);
1076 EXECUTE_IF_SET_IN_SPARSESET (unused_set
, j
)
1077 add_reg_note (curr_insn
, REG_UNUSED
, regno_reg_rtx
[j
]);
1080 if (bb_has_eh_pred (bb
))
1083 unsigned int regno
= EH_RETURN_DATA_REGNO (j
);
1085 if (regno
== INVALID_REGNUM
)
1087 make_hard_regno_live (regno
);
1090 /* Pseudos can't go in stack regs at the start of a basic block that
1091 is reached by an abnormal edge. Likewise for call clobbered regs,
1092 because caller-save, fixup_abnormal_edges and possibly the table
1093 driven EH machinery are not quite ready to handle such pseudos
1094 live across such edges. */
1095 if (bb_has_abnormal_pred (bb
))
1098 EXECUTE_IF_SET_IN_SPARSESET (pseudos_live
, px
)
1099 lra_reg_info
[px
].no_stack_p
= true;
1100 for (px
= FIRST_STACK_REG
; px
<= LAST_STACK_REG
; px
++)
1101 make_hard_regno_live (px
);
1103 /* No need to record conflicts for call clobbered regs if we
1104 have nonlocal labels around, as we don't ever try to
1105 allocate such regs in this case. */
1106 if (!cfun
->has_nonlocal_label
1107 && has_abnormal_call_or_eh_pred_edge_p (bb
))
1108 for (px
= 0; HARD_REGISTER_NUM_P (px
); px
++)
1109 if (call_used_regs
[px
]
1110 #ifdef REAL_PIC_OFFSET_TABLE_REGNUM
1111 /* We should create a conflict of PIC pseudo with PIC
1112 hard reg as PIC hard reg can have a wrong value after
1113 jump described by the abnormal edge. In this case we
1114 cannot allocate PIC hard reg to PIC pseudo as PIC
1115 pseudo will also have a wrong value. */
1116 || (px
== REAL_PIC_OFFSET_TABLE_REGNUM
1117 && pic_offset_table_rtx
!= NULL_RTX
1118 && !HARD_REGISTER_P (pic_offset_table_rtx
))
1121 make_hard_regno_live (px
);
1124 bool live_change_p
= false;
1125 /* Check if bb border live info was changed. */
1126 unsigned int live_pseudos_num
= 0;
1127 EXECUTE_IF_SET_IN_BITMAP (df_get_live_in (bb
),
1128 FIRST_PSEUDO_REGISTER
, j
, bi
)
1131 if (! sparseset_bit_p (pseudos_live
, j
))
1133 live_change_p
= true;
1134 if (lra_dump_file
!= NULL
)
1135 fprintf (lra_dump_file
,
1136 " r%d is removed as live at bb%d start\n", j
, bb
->index
);
1141 && sparseset_cardinality (pseudos_live
) != live_pseudos_num
)
1143 live_change_p
= true;
1144 if (lra_dump_file
!= NULL
)
1145 EXECUTE_IF_SET_IN_SPARSESET (pseudos_live
, j
)
1146 if (! bitmap_bit_p (df_get_live_in (bb
), j
))
1147 fprintf (lra_dump_file
,
1148 " r%d is added to live at bb%d start\n", j
, bb
->index
);
1150 /* See if we'll need an increment at the end of this basic block.
1151 An increment is needed if the PSEUDOS_LIVE set is not empty,
1152 to make sure the finish points are set up correctly. */
1153 need_curr_point_incr
= (sparseset_cardinality (pseudos_live
) > 0);
1155 EXECUTE_IF_SET_IN_SPARSESET (pseudos_live
, i
)
1157 update_pseudo_point (i
, curr_point
, DEF_POINT
);
1158 mark_pseudo_dead (i
);
1161 EXECUTE_IF_SET_IN_BITMAP (df_get_live_in (bb
), FIRST_PSEUDO_REGISTER
, j
, bi
)
1163 if (sparseset_cardinality (pseudos_live_through_calls
) == 0)
1165 if (sparseset_bit_p (pseudos_live_through_calls
, j
))
1166 check_pseudos_live_through_calls (j
, last_call_used_reg_set
, call_insn
);
1169 for (i
= 0; HARD_REGISTER_NUM_P (i
); ++i
)
1171 if (!TEST_HARD_REG_BIT (hard_regs_live
, i
))
1174 if (!TEST_HARD_REG_BIT (hard_regs_spilled_into
, i
))
1177 if (bitmap_bit_p (df_get_live_in (bb
), i
))
1180 live_change_p
= true;
1182 fprintf (lra_dump_file
,
1183 " hard reg r%d is added to live at bb%d start\n", i
,
1185 bitmap_set_bit (df_get_live_in (bb
), i
);
1188 if (need_curr_point_incr
)
1189 next_program_point (curr_point
, freq
);
1191 return live_change_p
;
1194 /* Compress pseudo live ranges by removing program points where
1195 nothing happens. Complexity of many algorithms in LRA is linear
1196 function of program points number. To speed up the code we try to
1197 minimize the number of the program points here. */
1199 remove_some_program_points_and_update_live_ranges (void)
1204 lra_live_range_t r
, prev_r
, next_r
;
1205 sbitmap_iterator sbi
;
1206 bool born_p
, dead_p
, prev_born_p
, prev_dead_p
;
1208 auto_sbitmap
born (lra_live_max_point
);
1209 auto_sbitmap
dead (lra_live_max_point
);
1210 bitmap_clear (born
);
1211 bitmap_clear (dead
);
1212 max_regno
= max_reg_num ();
1213 for (i
= FIRST_PSEUDO_REGISTER
; i
< (unsigned) max_regno
; i
++)
1215 for (r
= lra_reg_info
[i
].live_ranges
; r
!= NULL
; r
= r
->next
)
1217 lra_assert (r
->start
<= r
->finish
);
1218 bitmap_set_bit (born
, r
->start
);
1219 bitmap_set_bit (dead
, r
->finish
);
1222 auto_sbitmap
born_or_dead (lra_live_max_point
);
1223 bitmap_ior (born_or_dead
, born
, dead
);
1224 map
= XCNEWVEC (int, lra_live_max_point
);
1226 prev_born_p
= prev_dead_p
= false;
1227 EXECUTE_IF_SET_IN_BITMAP (born_or_dead
, 0, i
, sbi
)
1229 born_p
= bitmap_bit_p (born
, i
);
1230 dead_p
= bitmap_bit_p (dead
, i
);
1231 if ((prev_born_p
&& ! prev_dead_p
&& born_p
&& ! dead_p
)
1232 || (prev_dead_p
&& ! prev_born_p
&& dead_p
&& ! born_p
))
1235 lra_point_freq
[n
] = MAX (lra_point_freq
[n
], lra_point_freq
[i
]);
1240 lra_point_freq
[n
] = lra_point_freq
[i
];
1242 prev_born_p
= born_p
;
1243 prev_dead_p
= dead_p
;
1246 if (lra_dump_file
!= NULL
)
1247 fprintf (lra_dump_file
, "Compressing live ranges: from %d to %d - %d%%\n",
1248 lra_live_max_point
, n
,
1249 lra_live_max_point
? 100 * n
/ lra_live_max_point
: 100);
1250 if (n
< lra_live_max_point
)
1252 lra_live_max_point
= n
;
1253 for (i
= FIRST_PSEUDO_REGISTER
; i
< (unsigned) max_regno
; i
++)
1255 for (prev_r
= NULL
, r
= lra_reg_info
[i
].live_ranges
;
1260 r
->start
= map
[r
->start
];
1261 r
->finish
= map
[r
->finish
];
1262 if (prev_r
== NULL
|| prev_r
->start
> r
->finish
+ 1)
1267 prev_r
->start
= r
->start
;
1268 prev_r
->next
= next_r
;
1269 lra_live_range_pool
.remove (r
);
1276 /* Print live ranges R to file F. */
1278 lra_print_live_range_list (FILE *f
, lra_live_range_t r
)
1280 for (; r
!= NULL
; r
= r
->next
)
1281 fprintf (f
, " [%d..%d]", r
->start
, r
->finish
);
1286 debug (lra_live_range
&ref
)
1288 lra_print_live_range_list (stderr
, &ref
);
1292 debug (lra_live_range
*ptr
)
1297 fprintf (stderr
, "<nil>\n");
1300 /* Print live ranges R to stderr. */
1302 lra_debug_live_range_list (lra_live_range_t r
)
1304 lra_print_live_range_list (stderr
, r
);
1307 /* Print live ranges of pseudo REGNO to file F. */
1309 print_pseudo_live_ranges (FILE *f
, int regno
)
1311 if (lra_reg_info
[regno
].live_ranges
== NULL
)
1313 fprintf (f
, " r%d:", regno
);
1314 lra_print_live_range_list (f
, lra_reg_info
[regno
].live_ranges
);
1317 /* Print live ranges of pseudo REGNO to stderr. */
1319 lra_debug_pseudo_live_ranges (int regno
)
1321 print_pseudo_live_ranges (stderr
, regno
);
1324 /* Print live ranges of all pseudos to file F. */
1326 print_live_ranges (FILE *f
)
1330 max_regno
= max_reg_num ();
1331 for (i
= FIRST_PSEUDO_REGISTER
; i
< max_regno
; i
++)
1332 print_pseudo_live_ranges (f
, i
);
1335 /* Print live ranges of all pseudos to stderr. */
1337 lra_debug_live_ranges (void)
1339 print_live_ranges (stderr
);
1342 /* Compress pseudo live ranges. */
1344 compress_live_ranges (void)
1346 remove_some_program_points_and_update_live_ranges ();
1347 if (lra_dump_file
!= NULL
)
1349 fprintf (lra_dump_file
, "Ranges after the compression:\n");
1350 print_live_ranges (lra_dump_file
);
1356 /* The number of the current live range pass. */
1357 int lra_live_range_iter
;
1359 /* The function creates live ranges only for memory pseudos (or for
1360 all ones if ALL_P), set up CONFLICT_HARD_REGS for the pseudos. It
1361 also does dead insn elimination if DEAD_INSN_P and global live
1362 analysis only for pseudos and only if the pseudo live info was
1363 changed on a BB border. Return TRUE if the live info was
1366 lra_create_live_ranges_1 (bool all_p
, bool dead_insn_p
)
1369 int i
, hard_regno
, max_regno
= max_reg_num ();
1371 bool bb_live_change_p
, have_referenced_pseudos
= false;
1373 timevar_push (TV_LRA_CREATE_LIVE_RANGES
);
1375 complete_info_p
= all_p
;
1376 if (lra_dump_file
!= NULL
)
1377 fprintf (lra_dump_file
,
1378 "\n********** Pseudo live ranges #%d: **********\n\n",
1379 ++lra_live_range_iter
);
1380 memset (lra_hard_reg_usage
, 0, sizeof (lra_hard_reg_usage
));
1381 for (i
= 0; i
< max_regno
; i
++)
1383 lra_reg_info
[i
].live_ranges
= NULL
;
1384 CLEAR_HARD_REG_SET (lra_reg_info
[i
].conflict_hard_regs
);
1385 lra_reg_info
[i
].preferred_hard_regno1
= -1;
1386 lra_reg_info
[i
].preferred_hard_regno2
= -1;
1387 lra_reg_info
[i
].preferred_hard_regno_profit1
= 0;
1388 lra_reg_info
[i
].preferred_hard_regno_profit2
= 0;
1390 lra_reg_info
[i
].no_stack_p
= false;
1392 /* The biggest mode is already set but its value might be to
1393 conservative because of recent transformation. Here in this
1394 file we recalculate it again as it costs practically
1396 if (!HARD_REGISTER_NUM_P (i
) && regno_reg_rtx
[i
] != NULL_RTX
)
1397 lra_reg_info
[i
].biggest_mode
= GET_MODE (regno_reg_rtx
[i
]);
1399 lra_reg_info
[i
].biggest_mode
= VOIDmode
;
1400 lra_reg_info
[i
].call_insn
= NULL
;
1401 if (!HARD_REGISTER_NUM_P (i
)
1402 && lra_reg_info
[i
].nrefs
!= 0)
1404 if ((hard_regno
= reg_renumber
[i
]) >= 0)
1405 lra_hard_reg_usage
[hard_regno
] += lra_reg_info
[i
].freq
;
1406 have_referenced_pseudos
= true;
1411 /* Under some circumstances, we can have functions without pseudo
1412 registers. For such functions, lra_live_max_point will be 0,
1413 see e.g. PR55604, and there's nothing more to do for us here. */
1414 if (! have_referenced_pseudos
)
1416 timevar_pop (TV_LRA_CREATE_LIVE_RANGES
);
1420 pseudos_live
= sparseset_alloc (max_regno
);
1421 pseudos_live_through_calls
= sparseset_alloc (max_regno
);
1422 pseudos_live_through_setjumps
= sparseset_alloc (max_regno
);
1423 start_living
= sparseset_alloc (max_regno
);
1424 start_dying
= sparseset_alloc (max_regno
);
1425 dead_set
= sparseset_alloc (max_regno
);
1426 unused_set
= sparseset_alloc (max_regno
);
1428 unsigned new_length
= get_max_uid () * 2;
1429 point_freq_vec
.truncate (0);
1430 point_freq_vec
.reserve_exact (new_length
);
1431 lra_point_freq
= point_freq_vec
.address ();
1432 auto_vec
<int, 20> post_order_rev_cfg
;
1433 inverted_post_order_compute (&post_order_rev_cfg
);
1434 lra_assert (post_order_rev_cfg
.length () == (unsigned) n_basic_blocks_for_fn (cfun
));
1435 bb_live_change_p
= false;
1436 for (i
= post_order_rev_cfg
.length () - 1; i
>= 0; --i
)
1438 bb
= BASIC_BLOCK_FOR_FN (cfun
, post_order_rev_cfg
[i
]);
1439 if (bb
== EXIT_BLOCK_PTR_FOR_FN (cfun
) || bb
1440 == ENTRY_BLOCK_PTR_FOR_FN (cfun
))
1442 if (process_bb_lives (bb
, curr_point
, dead_insn_p
))
1443 bb_live_change_p
= true;
1445 if (bb_live_change_p
)
1447 /* We need to clear pseudo live info as some pseudos can
1448 disappear, e.g. pseudos with used equivalences. */
1449 FOR_EACH_BB_FN (bb
, cfun
)
1451 bitmap_clear_range (df_get_live_in (bb
), FIRST_PSEUDO_REGISTER
,
1452 max_regno
- FIRST_PSEUDO_REGISTER
);
1453 bitmap_clear_range (df_get_live_out (bb
), FIRST_PSEUDO_REGISTER
,
1454 max_regno
- FIRST_PSEUDO_REGISTER
);
1456 /* As we did not change CFG since LRA start we can use
1457 DF-infrastructure solver to solve live data flow problem. */
1458 for (int i
= 0; HARD_REGISTER_NUM_P (i
); ++i
)
1460 if (TEST_HARD_REG_BIT (hard_regs_spilled_into
, i
))
1461 bitmap_clear_bit (&all_hard_regs_bitmap
, i
);
1464 (DF_BACKWARD
, NULL
, live_con_fun_0
, live_con_fun_n
,
1465 live_trans_fun
, &all_blocks
,
1466 df_get_postorder (DF_BACKWARD
), df_get_n_blocks (DF_BACKWARD
));
1467 if (lra_dump_file
!= NULL
)
1469 fprintf (lra_dump_file
,
1470 "Global pseudo live data have been updated:\n");
1472 FOR_EACH_BB_FN (bb
, cfun
)
1474 bb_data_t bb_info
= get_bb_data (bb
);
1475 bitmap bb_livein
= df_get_live_in (bb
);
1476 bitmap bb_liveout
= df_get_live_out (bb
);
1478 fprintf (lra_dump_file
, "\nBB %d:\n", bb
->index
);
1479 lra_dump_bitmap_with_title (" gen:",
1480 &bb_info
->gen_pseudos
, bb
->index
);
1481 lra_dump_bitmap_with_title (" killed:",
1482 &bb_info
->killed_pseudos
, bb
->index
);
1483 lra_dump_bitmap_with_title (" livein:", bb_livein
, bb
->index
);
1484 lra_dump_bitmap_with_title (" liveout:", bb_liveout
, bb
->index
);
1488 lra_live_max_point
= curr_point
;
1489 if (lra_dump_file
!= NULL
)
1490 print_live_ranges (lra_dump_file
);
1492 sparseset_free (unused_set
);
1493 sparseset_free (dead_set
);
1494 sparseset_free (start_dying
);
1495 sparseset_free (start_living
);
1496 sparseset_free (pseudos_live_through_calls
);
1497 sparseset_free (pseudos_live_through_setjumps
);
1498 sparseset_free (pseudos_live
);
1499 compress_live_ranges ();
1500 timevar_pop (TV_LRA_CREATE_LIVE_RANGES
);
1501 return bb_live_change_p
;
1504 /* The main entry function creates live-ranges and other live info
1505 necessary for the assignment sub-pass. It uses
1506 lra_creates_live_ranges_1 -- so read comments for the
1509 lra_create_live_ranges (bool all_p
, bool dead_insn_p
)
1511 if (! lra_create_live_ranges_1 (all_p
, dead_insn_p
))
1513 if (lra_dump_file
!= NULL
)
1514 fprintf (lra_dump_file
, "Live info was changed -- recalculate it\n");
1515 /* Live info was changed on a bb border. It means that some info,
1516 e.g. about conflict regs, calls crossed, and live ranges may be
1517 wrong. We need this info for allocation. So recalculate it
1518 again but without removing dead insns which can change live info
1519 again. Repetitive live range calculations are expensive therefore
1520 we stop here as we already have correct info although some
1521 improvement in rare cases could be possible on this sub-pass if
1522 we do dead insn elimination again (still the improvement may
1524 lra_clear_live_ranges ();
1525 bool res
= lra_create_live_ranges_1 (all_p
, false);
1529 /* Finish all live ranges. */
1531 lra_clear_live_ranges (void)
1535 for (i
= 0; i
< max_reg_num (); i
++)
1536 free_live_range_list (lra_reg_info
[i
].live_ranges
);
1537 point_freq_vec
.release ();
1540 /* Initialize live ranges data once per function. */
1542 lra_live_ranges_init (void)
1544 bitmap_initialize (&temp_bitmap
, ®_obstack
);
1545 initiate_live_solver ();
1548 /* Finish live ranges data once per function. */
1550 lra_live_ranges_finish (void)
1552 finish_live_solver ();
1553 bitmap_clear (&temp_bitmap
);
1554 lra_live_range_pool
.release ();