1 /* IRA processing allocno lives to build allocno live ranges.
2 Copyright (C) 2006-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/>. */
23 #include "coretypes.h"
31 #include "insn-config.h"
35 #include "sparseset.h"
37 /* The code in this file is similar to one in global but the code
38 works on the allocno basis and creates live ranges instead of
39 pseudo-register conflicts. */
41 /* Program points are enumerated by numbers from range
42 0..IRA_MAX_POINT-1. There are approximately two times more program
43 points than insns. Program points are places in the program where
44 liveness info can be changed. In most general case (there are more
45 complicated cases too) some program points correspond to places
46 where input operand dies and other ones correspond to places where
47 output operands are born. */
50 /* Arrays of size IRA_MAX_POINT mapping a program point to the allocno
51 live ranges with given start/finish point. */
52 live_range_t
*ira_start_point_ranges
, *ira_finish_point_ranges
;
54 /* Number of the current program point. */
55 static int curr_point
;
57 /* Point where register pressure excess started or -1 if there is no
58 register pressure excess. Excess pressure for a register class at
59 some point means that there are more allocnos of given register
60 class living at the point than number of hard-registers of the
61 class available for the allocation. It is defined only for
63 static int high_pressure_start_point
[N_REG_CLASSES
];
65 /* Objects live at current point in the scan. */
66 static sparseset objects_live
;
68 /* A temporary bitmap used in functions that wish to avoid visiting an allocno
70 static sparseset allocnos_processed
;
72 /* Set of hard regs (except eliminable ones) currently live. */
73 static HARD_REG_SET hard_regs_live
;
75 /* The loop tree node corresponding to the current basic block. */
76 static ira_loop_tree_node_t curr_bb_node
;
78 /* The number of the last processed call. */
79 static int last_call_num
;
80 /* The number of last call at which given allocno was saved. */
81 static int *allocno_saved_at_call
;
83 /* The value of get_preferred_alternatives for the current instruction,
84 supplemental to recog_data. */
85 static alternative_mask preferred_alternatives
;
87 /* If non-NULL, the source operand of a register to register copy for which
88 we should not add a conflict with the copy's destination operand. */
89 static rtx ignore_reg_for_conflicts
;
91 /* Record hard register REGNO as now being live. */
93 make_hard_regno_live (int regno
)
95 SET_HARD_REG_BIT (hard_regs_live
, regno
);
98 /* Process the definition of hard register REGNO. This updates
99 hard_regs_live and hard reg conflict information for living allocnos. */
101 make_hard_regno_dead (int regno
)
104 EXECUTE_IF_SET_IN_SPARSESET (objects_live
, i
)
106 ira_object_t obj
= ira_object_id_map
[i
];
108 if (ignore_reg_for_conflicts
!= NULL_RTX
109 && REGNO (ignore_reg_for_conflicts
)
110 == (unsigned int) ALLOCNO_REGNO (OBJECT_ALLOCNO (obj
)))
113 SET_HARD_REG_BIT (OBJECT_CONFLICT_HARD_REGS (obj
), regno
);
114 SET_HARD_REG_BIT (OBJECT_TOTAL_CONFLICT_HARD_REGS (obj
), regno
);
116 CLEAR_HARD_REG_BIT (hard_regs_live
, regno
);
119 /* Record object OBJ as now being live. Set a bit for it in objects_live,
120 and start a new live range for it if necessary. */
122 make_object_live (ira_object_t obj
)
124 sparseset_set_bit (objects_live
, OBJECT_CONFLICT_ID (obj
));
126 live_range_t lr
= OBJECT_LIVE_RANGES (obj
);
128 || (lr
->finish
!= curr_point
&& lr
->finish
+ 1 != curr_point
))
129 ira_add_live_range_to_object (obj
, curr_point
, -1);
132 /* Update ALLOCNO_EXCESS_PRESSURE_POINTS_NUM for the allocno
133 associated with object OBJ. */
135 update_allocno_pressure_excess_length (ira_object_t obj
)
137 ira_allocno_t a
= OBJECT_ALLOCNO (obj
);
139 enum reg_class aclass
, pclass
, cl
;
142 aclass
= ALLOCNO_CLASS (a
);
143 pclass
= ira_pressure_class_translate
[aclass
];
145 (cl
= ira_reg_class_super_classes
[pclass
][i
]) != LIM_REG_CLASSES
;
148 if (! ira_reg_pressure_class_p
[cl
])
150 if (high_pressure_start_point
[cl
] < 0)
152 p
= OBJECT_LIVE_RANGES (obj
);
153 ira_assert (p
!= NULL
);
154 start
= (high_pressure_start_point
[cl
] > p
->start
155 ? high_pressure_start_point
[cl
] : p
->start
);
156 ALLOCNO_EXCESS_PRESSURE_POINTS_NUM (a
) += curr_point
- start
+ 1;
160 /* Process the definition of object OBJ, which is associated with allocno A.
161 This finishes the current live range for it. */
163 make_object_dead (ira_object_t obj
)
167 int ignore_regno
= -1;
168 int ignore_total_regno
= -1;
171 sparseset_clear_bit (objects_live
, OBJECT_CONFLICT_ID (obj
));
173 /* Check whether any part of IGNORE_REG_FOR_CONFLICTS already conflicts
175 if (ignore_reg_for_conflicts
!= NULL_RTX
176 && REGNO (ignore_reg_for_conflicts
) < FIRST_PSEUDO_REGISTER
)
178 end_regno
= END_REGNO (ignore_reg_for_conflicts
);
179 ignore_regno
= ignore_total_regno
= REGNO (ignore_reg_for_conflicts
);
181 for (regno
= ignore_regno
; regno
< end_regno
; regno
++)
183 if (TEST_HARD_REG_BIT (OBJECT_CONFLICT_HARD_REGS (obj
), regno
))
184 ignore_regno
= end_regno
;
185 if (TEST_HARD_REG_BIT (OBJECT_TOTAL_CONFLICT_HARD_REGS (obj
), regno
))
186 ignore_total_regno
= end_regno
;
190 IOR_HARD_REG_SET (OBJECT_CONFLICT_HARD_REGS (obj
), hard_regs_live
);
191 IOR_HARD_REG_SET (OBJECT_TOTAL_CONFLICT_HARD_REGS (obj
), hard_regs_live
);
193 /* If IGNORE_REG_FOR_CONFLICTS did not already conflict with OBJ, make
194 sure it still doesn't. */
195 for (regno
= ignore_regno
; regno
< end_regno
; regno
++)
196 CLEAR_HARD_REG_BIT (OBJECT_CONFLICT_HARD_REGS (obj
), regno
);
197 for (regno
= ignore_total_regno
; regno
< end_regno
; regno
++)
198 CLEAR_HARD_REG_BIT (OBJECT_TOTAL_CONFLICT_HARD_REGS (obj
), regno
);
200 lr
= OBJECT_LIVE_RANGES (obj
);
201 ira_assert (lr
!= NULL
);
202 lr
->finish
= curr_point
;
203 update_allocno_pressure_excess_length (obj
);
206 /* The current register pressures for each pressure class for the current
208 static int curr_reg_pressure
[N_REG_CLASSES
];
210 /* Record that register pressure for PCLASS increased by N registers.
211 Update the current register pressure, maximal register pressure for
212 the current BB and the start point of the register pressure
215 inc_register_pressure (enum reg_class pclass
, int n
)
221 (cl
= ira_reg_class_super_classes
[pclass
][i
]) != LIM_REG_CLASSES
;
224 if (! ira_reg_pressure_class_p
[cl
])
226 curr_reg_pressure
[cl
] += n
;
227 if (high_pressure_start_point
[cl
] < 0
228 && (curr_reg_pressure
[cl
] > ira_class_hard_regs_num
[cl
]))
229 high_pressure_start_point
[cl
] = curr_point
;
230 if (curr_bb_node
->reg_pressure
[cl
] < curr_reg_pressure
[cl
])
231 curr_bb_node
->reg_pressure
[cl
] = curr_reg_pressure
[cl
];
235 /* Record that register pressure for PCLASS has decreased by NREGS
236 registers; update current register pressure, start point of the
237 register pressure excess, and register pressure excess length for
241 dec_register_pressure (enum reg_class pclass
, int nregs
)
249 (cl
= ira_reg_class_super_classes
[pclass
][i
]) != LIM_REG_CLASSES
;
252 if (! ira_reg_pressure_class_p
[cl
])
254 curr_reg_pressure
[cl
] -= nregs
;
255 ira_assert (curr_reg_pressure
[cl
] >= 0);
256 if (high_pressure_start_point
[cl
] >= 0
257 && curr_reg_pressure
[cl
] <= ira_class_hard_regs_num
[cl
])
262 EXECUTE_IF_SET_IN_SPARSESET (objects_live
, j
)
263 update_allocno_pressure_excess_length (ira_object_id_map
[j
]);
265 (cl
= ira_reg_class_super_classes
[pclass
][i
]) != LIM_REG_CLASSES
;
268 if (! ira_reg_pressure_class_p
[cl
])
270 if (high_pressure_start_point
[cl
] >= 0
271 && curr_reg_pressure
[cl
] <= ira_class_hard_regs_num
[cl
])
272 high_pressure_start_point
[cl
] = -1;
277 /* Determine from the objects_live bitmap whether REGNO is currently live,
278 and occupies only one object. Return false if we have no information. */
280 pseudo_regno_single_word_and_live_p (int regno
)
282 ira_allocno_t a
= ira_curr_regno_allocno_map
[regno
];
287 if (ALLOCNO_NUM_OBJECTS (a
) > 1)
290 obj
= ALLOCNO_OBJECT (a
, 0);
292 return sparseset_bit_p (objects_live
, OBJECT_CONFLICT_ID (obj
));
295 /* Mark the pseudo register REGNO as live. Update all information about
296 live ranges and register pressure. */
298 mark_pseudo_regno_live (int regno
)
300 ira_allocno_t a
= ira_curr_regno_allocno_map
[regno
];
301 enum reg_class pclass
;
307 /* Invalidate because it is referenced. */
308 allocno_saved_at_call
[ALLOCNO_NUM (a
)] = 0;
310 n
= ALLOCNO_NUM_OBJECTS (a
);
311 pclass
= ira_pressure_class_translate
[ALLOCNO_CLASS (a
)];
312 nregs
= ira_reg_class_max_nregs
[ALLOCNO_CLASS (a
)][ALLOCNO_MODE (a
)];
315 /* We track every subobject separately. */
316 gcc_assert (nregs
== n
);
320 for (i
= 0; i
< n
; i
++)
322 ira_object_t obj
= ALLOCNO_OBJECT (a
, i
);
324 if (sparseset_bit_p (objects_live
, OBJECT_CONFLICT_ID (obj
)))
327 inc_register_pressure (pclass
, nregs
);
328 make_object_live (obj
);
332 /* Like mark_pseudo_regno_live, but try to only mark one subword of
333 the pseudo as live. SUBWORD indicates which; a value of 0
334 indicates the low part. */
336 mark_pseudo_regno_subword_live (int regno
, int subword
)
338 ira_allocno_t a
= ira_curr_regno_allocno_map
[regno
];
340 enum reg_class pclass
;
346 /* Invalidate because it is referenced. */
347 allocno_saved_at_call
[ALLOCNO_NUM (a
)] = 0;
349 n
= ALLOCNO_NUM_OBJECTS (a
);
352 mark_pseudo_regno_live (regno
);
356 pclass
= ira_pressure_class_translate
[ALLOCNO_CLASS (a
)];
358 (n
== ira_reg_class_max_nregs
[ALLOCNO_CLASS (a
)][ALLOCNO_MODE (a
)]);
359 obj
= ALLOCNO_OBJECT (a
, subword
);
361 if (sparseset_bit_p (objects_live
, OBJECT_CONFLICT_ID (obj
)))
364 inc_register_pressure (pclass
, 1);
365 make_object_live (obj
);
368 /* Mark the register REG as live. Store a 1 in hard_regs_live for
369 this register, record how many consecutive hardware registers it
372 mark_hard_reg_live (rtx reg
)
374 int regno
= REGNO (reg
);
376 if (! TEST_HARD_REG_BIT (ira_no_alloc_regs
, regno
))
378 int last
= END_REGNO (reg
);
379 enum reg_class aclass
, pclass
;
383 if (! TEST_HARD_REG_BIT (hard_regs_live
, regno
)
384 && ! TEST_HARD_REG_BIT (eliminable_regset
, regno
))
386 aclass
= ira_hard_regno_allocno_class
[regno
];
387 pclass
= ira_pressure_class_translate
[aclass
];
388 inc_register_pressure (pclass
, 1);
389 make_hard_regno_live (regno
);
396 /* Mark a pseudo, or one of its subwords, as live. REGNO is the pseudo's
397 register number; ORIG_REG is the access in the insn, which may be a
400 mark_pseudo_reg_live (rtx orig_reg
, unsigned regno
)
402 if (read_modify_subreg_p (orig_reg
))
404 mark_pseudo_regno_subword_live (regno
,
405 subreg_lowpart_p (orig_reg
) ? 0 : 1);
408 mark_pseudo_regno_live (regno
);
411 /* Mark the register referenced by use or def REF as live. */
413 mark_ref_live (df_ref ref
)
415 rtx reg
= DF_REF_REG (ref
);
418 if (GET_CODE (reg
) == SUBREG
)
419 reg
= SUBREG_REG (reg
);
421 if (REGNO (reg
) >= FIRST_PSEUDO_REGISTER
)
422 mark_pseudo_reg_live (orig_reg
, REGNO (reg
));
424 mark_hard_reg_live (reg
);
427 /* Mark the pseudo register REGNO as dead. Update all information about
428 live ranges and register pressure. */
430 mark_pseudo_regno_dead (int regno
)
432 ira_allocno_t a
= ira_curr_regno_allocno_map
[regno
];
439 /* Invalidate because it is referenced. */
440 allocno_saved_at_call
[ALLOCNO_NUM (a
)] = 0;
442 n
= ALLOCNO_NUM_OBJECTS (a
);
443 cl
= ira_pressure_class_translate
[ALLOCNO_CLASS (a
)];
444 nregs
= ira_reg_class_max_nregs
[ALLOCNO_CLASS (a
)][ALLOCNO_MODE (a
)];
447 /* We track every subobject separately. */
448 gcc_assert (nregs
== n
);
451 for (i
= 0; i
< n
; i
++)
453 ira_object_t obj
= ALLOCNO_OBJECT (a
, i
);
454 if (!sparseset_bit_p (objects_live
, OBJECT_CONFLICT_ID (obj
)))
457 dec_register_pressure (cl
, nregs
);
458 make_object_dead (obj
);
462 /* Like mark_pseudo_regno_dead, but called when we know that only part of the
463 register dies. SUBWORD indicates which; a value of 0 indicates the low part. */
465 mark_pseudo_regno_subword_dead (int regno
, int subword
)
467 ira_allocno_t a
= ira_curr_regno_allocno_map
[regno
];
475 /* Invalidate because it is referenced. */
476 allocno_saved_at_call
[ALLOCNO_NUM (a
)] = 0;
478 n
= ALLOCNO_NUM_OBJECTS (a
);
480 /* The allocno as a whole doesn't die in this case. */
483 cl
= ira_pressure_class_translate
[ALLOCNO_CLASS (a
)];
485 (n
== ira_reg_class_max_nregs
[ALLOCNO_CLASS (a
)][ALLOCNO_MODE (a
)]);
487 obj
= ALLOCNO_OBJECT (a
, subword
);
488 if (!sparseset_bit_p (objects_live
, OBJECT_CONFLICT_ID (obj
)))
491 dec_register_pressure (cl
, 1);
492 make_object_dead (obj
);
495 /* Process the definition of hard register REG. This updates hard_regs_live
496 and hard reg conflict information for living allocnos. */
498 mark_hard_reg_dead (rtx reg
)
500 int regno
= REGNO (reg
);
502 if (! TEST_HARD_REG_BIT (ira_no_alloc_regs
, regno
))
504 int last
= END_REGNO (reg
);
505 enum reg_class aclass
, pclass
;
509 if (TEST_HARD_REG_BIT (hard_regs_live
, regno
))
511 aclass
= ira_hard_regno_allocno_class
[regno
];
512 pclass
= ira_pressure_class_translate
[aclass
];
513 dec_register_pressure (pclass
, 1);
514 make_hard_regno_dead (regno
);
521 /* Mark a pseudo, or one of its subwords, as dead. REGNO is the pseudo's
522 register number; ORIG_REG is the access in the insn, which may be a
525 mark_pseudo_reg_dead (rtx orig_reg
, unsigned regno
)
527 if (read_modify_subreg_p (orig_reg
))
529 mark_pseudo_regno_subword_dead (regno
,
530 subreg_lowpart_p (orig_reg
) ? 0 : 1);
533 mark_pseudo_regno_dead (regno
);
536 /* Mark the register referenced by definition DEF as dead, if the
537 definition is a total one. */
539 mark_ref_dead (df_ref def
)
541 rtx reg
= DF_REF_REG (def
);
544 if (DF_REF_FLAGS_IS_SET (def
, DF_REF_CONDITIONAL
))
547 if (GET_CODE (reg
) == SUBREG
)
548 reg
= SUBREG_REG (reg
);
550 if (DF_REF_FLAGS_IS_SET (def
, DF_REF_PARTIAL
)
551 && (GET_CODE (orig_reg
) != SUBREG
552 || REGNO (reg
) < FIRST_PSEUDO_REGISTER
553 || !read_modify_subreg_p (orig_reg
)))
556 if (REGNO (reg
) >= FIRST_PSEUDO_REGISTER
)
557 mark_pseudo_reg_dead (orig_reg
, REGNO (reg
));
559 mark_hard_reg_dead (reg
);
562 /* If REG is a pseudo or a subreg of it, and the class of its allocno
563 intersects CL, make a conflict with pseudo DREG. ORIG_DREG is the
564 rtx actually accessed, it may be identical to DREG or a subreg of it.
565 Advance the current program point before making the conflict if
566 ADVANCE_P. Return TRUE if we will need to advance the current
569 make_pseudo_conflict (rtx reg
, enum reg_class cl
, rtx dreg
, rtx orig_dreg
,
575 if (GET_CODE (reg
) == SUBREG
)
576 reg
= SUBREG_REG (reg
);
578 if (! REG_P (reg
) || REGNO (reg
) < FIRST_PSEUDO_REGISTER
)
581 a
= ira_curr_regno_allocno_map
[REGNO (reg
)];
582 if (! reg_classes_intersect_p (cl
, ALLOCNO_CLASS (a
)))
588 mark_pseudo_reg_live (orig_reg
, REGNO (reg
));
589 mark_pseudo_reg_live (orig_dreg
, REGNO (dreg
));
590 mark_pseudo_reg_dead (orig_reg
, REGNO (reg
));
591 mark_pseudo_reg_dead (orig_dreg
, REGNO (dreg
));
596 /* Check and make if necessary conflicts for pseudo DREG of class
597 DEF_CL of the current insn with input operand USE of class USE_CL.
598 ORIG_DREG is the rtx actually accessed, it may be identical to
599 DREG or a subreg of it. Advance the current program point before
600 making the conflict if ADVANCE_P. Return TRUE if we will need to
601 advance the current program point. */
603 check_and_make_def_use_conflict (rtx dreg
, rtx orig_dreg
,
604 enum reg_class def_cl
, int use
,
605 enum reg_class use_cl
, bool advance_p
)
607 if (! reg_classes_intersect_p (def_cl
, use_cl
))
610 advance_p
= make_pseudo_conflict (recog_data
.operand
[use
],
611 use_cl
, dreg
, orig_dreg
, advance_p
);
613 /* Reload may end up swapping commutative operands, so you
614 have to take both orderings into account. The
615 constraints for the two operands can be completely
616 different. (Indeed, if the constraints for the two
617 operands are the same for all alternatives, there's no
618 point marking them as commutative.) */
619 if (use
< recog_data
.n_operands
- 1
620 && recog_data
.constraints
[use
][0] == '%')
622 = make_pseudo_conflict (recog_data
.operand
[use
+ 1],
623 use_cl
, dreg
, orig_dreg
, advance_p
);
625 && recog_data
.constraints
[use
- 1][0] == '%')
627 = make_pseudo_conflict (recog_data
.operand
[use
- 1],
628 use_cl
, dreg
, orig_dreg
, advance_p
);
632 /* Check and make if necessary conflicts for definition DEF of class
633 DEF_CL of the current insn with input operands. Process only
634 constraints of alternative ALT. */
636 check_and_make_def_conflict (int alt
, int def
, enum reg_class def_cl
)
640 enum reg_class use_cl
, acl
;
642 rtx dreg
= recog_data
.operand
[def
];
643 rtx orig_dreg
= dreg
;
645 if (def_cl
== NO_REGS
)
648 if (GET_CODE (dreg
) == SUBREG
)
649 dreg
= SUBREG_REG (dreg
);
651 if (! REG_P (dreg
) || REGNO (dreg
) < FIRST_PSEUDO_REGISTER
)
654 a
= ira_curr_regno_allocno_map
[REGNO (dreg
)];
655 acl
= ALLOCNO_CLASS (a
);
656 if (! reg_classes_intersect_p (acl
, def_cl
))
661 int n_operands
= recog_data
.n_operands
;
662 const operand_alternative
*op_alt
= &recog_op_alt
[alt
* n_operands
];
663 for (use
= 0; use
< n_operands
; use
++)
667 if (use
== def
|| recog_data
.operand_type
[use
] == OP_OUT
)
670 if (op_alt
[use
].anything_ok
)
673 use_cl
= op_alt
[use
].cl
;
675 /* If there's any alternative that allows USE to match DEF, do not
676 record a conflict. If that causes us to create an invalid
677 instruction due to the earlyclobber, reload must fix it up. */
678 for (alt1
= 0; alt1
< recog_data
.n_alternatives
; alt1
++)
680 if (!TEST_BIT (preferred_alternatives
, alt1
))
682 const operand_alternative
*op_alt1
683 = &recog_op_alt
[alt1
* n_operands
];
684 if (op_alt1
[use
].matches
== def
685 || (use
< n_operands
- 1
686 && recog_data
.constraints
[use
][0] == '%'
687 && op_alt1
[use
+ 1].matches
== def
)
689 && recog_data
.constraints
[use
- 1][0] == '%'
690 && op_alt1
[use
- 1].matches
== def
))
694 if (alt1
< recog_data
.n_alternatives
)
697 advance_p
= check_and_make_def_use_conflict (dreg
, orig_dreg
, def_cl
,
698 use
, use_cl
, advance_p
);
700 if ((use_match
= op_alt
[use
].matches
) >= 0)
702 if (use_match
== def
)
705 if (op_alt
[use_match
].anything_ok
)
708 use_cl
= op_alt
[use_match
].cl
;
709 advance_p
= check_and_make_def_use_conflict (dreg
, orig_dreg
, def_cl
,
710 use
, use_cl
, advance_p
);
715 /* Make conflicts of early clobber pseudo registers of the current
716 insn with its inputs. Avoid introducing unnecessary conflicts by
717 checking classes of the constraints and pseudos because otherwise
718 significant code degradation is possible for some targets. */
720 make_early_clobber_and_input_conflicts (void)
724 enum reg_class def_cl
;
726 int n_alternatives
= recog_data
.n_alternatives
;
727 int n_operands
= recog_data
.n_operands
;
728 const operand_alternative
*op_alt
= recog_op_alt
;
729 for (alt
= 0; alt
< n_alternatives
; alt
++, op_alt
+= n_operands
)
730 if (TEST_BIT (preferred_alternatives
, alt
))
731 for (def
= 0; def
< n_operands
; def
++)
734 if (op_alt
[def
].earlyclobber
)
736 if (op_alt
[def
].anything_ok
)
739 def_cl
= op_alt
[def
].cl
;
740 check_and_make_def_conflict (alt
, def
, def_cl
);
742 if ((def_match
= op_alt
[def
].matches
) >= 0
743 && (op_alt
[def_match
].earlyclobber
744 || op_alt
[def
].earlyclobber
))
746 if (op_alt
[def_match
].anything_ok
)
749 def_cl
= op_alt
[def_match
].cl
;
750 check_and_make_def_conflict (alt
, def
, def_cl
);
755 /* Mark early clobber hard registers of the current INSN as live (if
756 LIVE_P) or dead. Return true if there are such registers. */
758 mark_hard_reg_early_clobbers (rtx_insn
*insn
, bool live_p
)
763 FOR_EACH_INSN_DEF (def
, insn
)
764 if (DF_REF_FLAGS_IS_SET (def
, DF_REF_MUST_CLOBBER
))
766 rtx dreg
= DF_REF_REG (def
);
768 if (GET_CODE (dreg
) == SUBREG
)
769 dreg
= SUBREG_REG (dreg
);
770 if (! REG_P (dreg
) || REGNO (dreg
) >= FIRST_PSEUDO_REGISTER
)
773 /* Hard register clobbers are believed to be early clobber
774 because there is no way to say that non-operand hard
775 register clobbers are not early ones. */
786 /* Checks that CONSTRAINTS permits to use only one hard register. If
787 it is so, the function returns the class of the hard register.
788 Otherwise it returns NO_REGS. */
789 static enum reg_class
790 single_reg_class (const char *constraints
, rtx op
, rtx equiv_const
)
793 enum reg_class cl
, next_cl
;
794 enum constraint_num cn
;
797 alternative_mask preferred
= preferred_alternatives
;
798 for (; (c
= *constraints
); constraints
+= CONSTRAINT_LEN (c
, constraints
))
800 preferred
&= ~ALTERNATIVE_BIT (0);
803 else if (preferred
& 1)
810 /* ??? Is this the best way to handle memory constraints? */
811 cn
= lookup_constraint (constraints
);
812 if (insn_extra_memory_constraint (cn
)
813 || insn_extra_special_memory_constraint (cn
)
814 || insn_extra_address_constraint (cn
))
816 if (constraint_satisfied_p (op
, cn
)
817 || (equiv_const
!= NULL_RTX
818 && CONSTANT_P (equiv_const
)
819 && constraint_satisfied_p (equiv_const
, cn
)))
821 next_cl
= reg_class_for_constraint (cn
);
822 if (next_cl
== NO_REGS
)
825 ? ira_class_singleton
[next_cl
][GET_MODE (op
)] < 0
826 : (ira_class_singleton
[cl
][GET_MODE (op
)]
827 != ira_class_singleton
[next_cl
][GET_MODE (op
)]))
832 case '0': case '1': case '2': case '3': case '4':
833 case '5': case '6': case '7': case '8': case '9':
835 = single_reg_class (recog_data
.constraints
[c
- '0'],
836 recog_data
.operand
[c
- '0'], NULL_RTX
);
838 ? ira_class_singleton
[next_cl
][GET_MODE (op
)] < 0
839 : (ira_class_singleton
[cl
][GET_MODE (op
)]
840 != ira_class_singleton
[next_cl
][GET_MODE (op
)]))
848 /* The function checks that operand OP_NUM of the current insn can use
849 only one hard register. If it is so, the function returns the
850 class of the hard register. Otherwise it returns NO_REGS. */
851 static enum reg_class
852 single_reg_operand_class (int op_num
)
854 if (op_num
< 0 || recog_data
.n_alternatives
== 0)
856 return single_reg_class (recog_data
.constraints
[op_num
],
857 recog_data
.operand
[op_num
], NULL_RTX
);
860 /* The function sets up hard register set *SET to hard registers which
861 might be used by insn reloads because the constraints are too
864 ira_implicitly_set_insn_hard_regs (HARD_REG_SET
*set
,
865 alternative_mask preferred
)
872 CLEAR_HARD_REG_SET (*set
);
873 for (i
= 0; i
< recog_data
.n_operands
; i
++)
875 op
= recog_data
.operand
[i
];
877 if (GET_CODE (op
) == SUBREG
)
878 op
= SUBREG_REG (op
);
880 if (GET_CODE (op
) == SCRATCH
881 || (REG_P (op
) && (regno
= REGNO (op
)) >= FIRST_PSEUDO_REGISTER
))
883 const char *p
= recog_data
.constraints
[i
];
885 mode
= (GET_CODE (op
) == SCRATCH
886 ? GET_MODE (op
) : PSEUDO_REGNO_MODE (regno
));
888 for (; (c
= *p
); p
+= CONSTRAINT_LEN (c
, p
))
890 preferred
&= ~ALTERNATIVE_BIT (0);
893 else if (preferred
& 1)
895 cl
= reg_class_for_constraint (lookup_constraint (p
));
898 /* There is no register pressure problem if all of the
899 regs in this class are fixed. */
900 int regno
= ira_class_singleton
[cl
][mode
];
902 add_to_hard_reg_set (set
, mode
, regno
);
908 /* Processes input operands, if IN_P, or output operands otherwise of
909 the current insn with FREQ to find allocno which can use only one
910 hard register and makes other currently living allocnos conflicting
911 with the hard register. */
913 process_single_reg_class_operands (bool in_p
, int freq
)
919 ira_allocno_t operand_a
, a
;
921 for (i
= 0; i
< recog_data
.n_operands
; i
++)
923 operand
= recog_data
.operand
[i
];
924 if (in_p
&& recog_data
.operand_type
[i
] != OP_IN
925 && recog_data
.operand_type
[i
] != OP_INOUT
)
927 if (! in_p
&& recog_data
.operand_type
[i
] != OP_OUT
928 && recog_data
.operand_type
[i
] != OP_INOUT
)
930 cl
= single_reg_operand_class (i
);
936 if (GET_CODE (operand
) == SUBREG
)
937 operand
= SUBREG_REG (operand
);
940 && (regno
= REGNO (operand
)) >= FIRST_PSEUDO_REGISTER
)
942 enum reg_class aclass
;
944 operand_a
= ira_curr_regno_allocno_map
[regno
];
945 aclass
= ALLOCNO_CLASS (operand_a
);
946 if (ira_class_subset_p
[cl
][aclass
])
948 /* View the desired allocation of OPERAND as:
954 (subreg:YMODE (reg:XMODE XREGNO) OFFSET). */
955 machine_mode ymode
, xmode
;
959 xmode
= recog_data
.operand_mode
[i
];
960 xregno
= ira_class_singleton
[cl
][xmode
];
961 gcc_assert (xregno
>= 0);
962 ymode
= ALLOCNO_MODE (operand_a
);
963 offset
= subreg_lowpart_offset (ymode
, xmode
);
964 yregno
= simplify_subreg_regno (xregno
, xmode
, offset
, ymode
);
966 && ira_class_hard_reg_index
[aclass
][yregno
] >= 0)
970 ira_allocate_and_set_costs
971 (&ALLOCNO_CONFLICT_HARD_REG_COSTS (operand_a
),
973 ira_init_register_move_cost_if_necessary (xmode
);
975 ? ira_register_move_cost
[xmode
][aclass
][cl
]
976 : ira_register_move_cost
[xmode
][cl
][aclass
]);
977 ALLOCNO_CONFLICT_HARD_REG_COSTS (operand_a
)
978 [ira_class_hard_reg_index
[aclass
][yregno
]] -= cost
;
983 EXECUTE_IF_SET_IN_SPARSESET (objects_live
, px
)
985 ira_object_t obj
= ira_object_id_map
[px
];
986 a
= OBJECT_ALLOCNO (obj
);
989 /* We could increase costs of A instead of making it
990 conflicting with the hard register. But it works worse
991 because it will be spilled in reload in anyway. */
992 IOR_HARD_REG_SET (OBJECT_CONFLICT_HARD_REGS (obj
),
993 reg_class_contents
[cl
]);
994 IOR_HARD_REG_SET (OBJECT_TOTAL_CONFLICT_HARD_REGS (obj
),
995 reg_class_contents
[cl
]);
1001 /* Look through the CALL_INSN_FUNCTION_USAGE of a call insn INSN, and see if
1002 we find a SET rtx that we can use to deduce that a register can be cheaply
1003 caller-saved. Return such a register, or NULL_RTX if none is found. */
1005 find_call_crossed_cheap_reg (rtx_insn
*insn
)
1007 rtx cheap_reg
= NULL_RTX
;
1008 rtx exp
= CALL_INSN_FUNCTION_USAGE (insn
);
1012 rtx x
= XEXP (exp
, 0);
1013 if (GET_CODE (x
) == SET
)
1018 exp
= XEXP (exp
, 1);
1022 basic_block bb
= BLOCK_FOR_INSN (insn
);
1023 rtx reg
= SET_SRC (exp
);
1024 rtx_insn
*prev
= PREV_INSN (insn
);
1025 while (prev
&& !(INSN_P (prev
)
1026 && BLOCK_FOR_INSN (prev
) != bb
))
1028 if (NONDEBUG_INSN_P (prev
))
1030 rtx set
= single_set (prev
);
1032 if (set
&& rtx_equal_p (SET_DEST (set
), reg
))
1034 rtx src
= SET_SRC (set
);
1035 if (!REG_P (src
) || HARD_REGISTER_P (src
)
1036 || !pseudo_regno_single_word_and_live_p (REGNO (src
)))
1038 if (!modified_between_p (src
, prev
, insn
))
1042 if (set
&& rtx_equal_p (SET_SRC (set
), reg
))
1044 rtx dest
= SET_DEST (set
);
1045 if (!REG_P (dest
) || HARD_REGISTER_P (dest
)
1046 || !pseudo_regno_single_word_and_live_p (REGNO (dest
)))
1048 if (!modified_between_p (dest
, prev
, insn
))
1053 if (reg_set_p (reg
, prev
))
1056 prev
= PREV_INSN (prev
);
1062 /* Determine whether INSN is a register to register copy of the type where
1063 we do not need to make the source and destiniation registers conflict.
1064 If this is a copy instruction, then return the source reg. Otherwise,
1067 non_conflicting_reg_copy_p (rtx_insn
*insn
)
1069 /* Reload has issues with overlapping pseudos being assigned to the
1070 same hard register, so don't allow it. See PR87600 for details. */
1071 if (!targetm
.lra_p ())
1074 rtx set
= single_set (insn
);
1076 /* Disallow anything other than a simple register to register copy
1077 that has no side effects. */
1079 || !REG_P (SET_DEST (set
))
1080 || !REG_P (SET_SRC (set
))
1081 || side_effects_p (set
))
1084 int dst_regno
= REGNO (SET_DEST (set
));
1085 int src_regno
= REGNO (SET_SRC (set
));
1086 machine_mode mode
= GET_MODE (SET_DEST (set
));
1088 /* By definition, a register does not conflict with itself, therefore we
1089 do not have to handle it specially. Returning NULL_RTX now, helps
1090 simplify the callers of this function. */
1091 if (dst_regno
== src_regno
)
1094 /* Computing conflicts for register pairs is difficult to get right, so
1095 for now, disallow it. */
1096 if ((HARD_REGISTER_NUM_P (dst_regno
)
1097 && hard_regno_nregs (dst_regno
, mode
) != 1)
1098 || (HARD_REGISTER_NUM_P (src_regno
)
1099 && hard_regno_nregs (src_regno
, mode
) != 1))
1102 return SET_SRC (set
);
1105 /* Process insns of the basic block given by its LOOP_TREE_NODE to
1106 update allocno live ranges, allocno hard register conflicts,
1107 intersected calls, and register pressure info for allocnos for the
1108 basic block for and regions containing the basic block. */
1110 process_bb_node_lives (ira_loop_tree_node_t loop_tree_node
)
1117 bitmap reg_live_out
;
1121 bb
= loop_tree_node
->bb
;
1124 for (i
= 0; i
< ira_pressure_classes_num
; i
++)
1126 curr_reg_pressure
[ira_pressure_classes
[i
]] = 0;
1127 high_pressure_start_point
[ira_pressure_classes
[i
]] = -1;
1129 curr_bb_node
= loop_tree_node
;
1130 reg_live_out
= df_get_live_out (bb
);
1131 sparseset_clear (objects_live
);
1132 REG_SET_TO_HARD_REG_SET (hard_regs_live
, reg_live_out
);
1133 AND_COMPL_HARD_REG_SET (hard_regs_live
, eliminable_regset
);
1134 AND_COMPL_HARD_REG_SET (hard_regs_live
, ira_no_alloc_regs
);
1135 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1136 if (TEST_HARD_REG_BIT (hard_regs_live
, i
))
1138 enum reg_class aclass
, pclass
, cl
;
1140 aclass
= ira_allocno_class_translate
[REGNO_REG_CLASS (i
)];
1141 pclass
= ira_pressure_class_translate
[aclass
];
1143 (cl
= ira_reg_class_super_classes
[pclass
][j
])
1147 if (! ira_reg_pressure_class_p
[cl
])
1149 curr_reg_pressure
[cl
]++;
1150 if (curr_bb_node
->reg_pressure
[cl
] < curr_reg_pressure
[cl
])
1151 curr_bb_node
->reg_pressure
[cl
] = curr_reg_pressure
[cl
];
1152 ira_assert (curr_reg_pressure
[cl
]
1153 <= ira_class_hard_regs_num
[cl
]);
1156 EXECUTE_IF_SET_IN_BITMAP (reg_live_out
, FIRST_PSEUDO_REGISTER
, j
, bi
)
1157 mark_pseudo_regno_live (j
);
1159 freq
= REG_FREQ_FROM_BB (bb
);
1163 /* Invalidate all allocno_saved_at_call entries. */
1166 /* Scan the code of this basic block, noting which allocnos and
1167 hard regs are born or die.
1169 Note that this loop treats uninitialized values as live until
1170 the beginning of the block. For example, if an instruction
1171 uses (reg:DI foo), and only (subreg:SI (reg:DI foo) 0) is ever
1172 set, FOO will remain live until the beginning of the block.
1173 Likewise if FOO is not set at all. This is unnecessarily
1174 pessimistic, but it probably doesn't matter much in practice. */
1175 FOR_BB_INSNS_REVERSE (bb
, insn
)
1181 if (!NONDEBUG_INSN_P (insn
))
1184 if (internal_flag_ira_verbose
> 2 && ira_dump_file
!= NULL
)
1185 fprintf (ira_dump_file
, " Insn %u(l%d): point = %d\n",
1186 INSN_UID (insn
), loop_tree_node
->parent
->loop_num
,
1189 call_p
= CALL_P (insn
);
1190 ignore_reg_for_conflicts
= non_conflicting_reg_copy_p (insn
);
1192 /* Mark each defined value as live. We need to do this for
1193 unused values because they still conflict with quantities
1194 that are live at the time of the definition.
1196 Ignore DF_REF_MAY_CLOBBERs on a call instruction. Such
1197 references represent the effect of the called function
1198 on a call-clobbered register. Marking the register as
1199 live would stop us from allocating it to a call-crossing
1201 FOR_EACH_INSN_DEF (def
, insn
)
1202 if (!call_p
|| !DF_REF_FLAGS_IS_SET (def
, DF_REF_MAY_CLOBBER
))
1203 mark_ref_live (def
);
1205 /* If INSN has multiple outputs, then any value used in one
1206 of the outputs conflicts with the other outputs. Model this
1207 by making the used value live during the output phase.
1209 It is unsafe to use !single_set here since it will ignore
1210 an unused output. Just because an output is unused does
1211 not mean the compiler can assume the side effect will not
1212 occur. Consider if ALLOCNO appears in the address of an
1213 output and we reload the output. If we allocate ALLOCNO
1214 to the same hard register as an unused output we could
1215 set the hard register before the output reload insn. */
1216 if (GET_CODE (PATTERN (insn
)) == PARALLEL
&& multiple_sets (insn
))
1217 FOR_EACH_INSN_USE (use
, insn
)
1222 reg
= DF_REF_REG (use
);
1223 for (i
= XVECLEN (PATTERN (insn
), 0) - 1; i
>= 0; i
--)
1227 set
= XVECEXP (PATTERN (insn
), 0, i
);
1228 if (GET_CODE (set
) == SET
1229 && reg_overlap_mentioned_p (reg
, SET_DEST (set
)))
1231 /* After the previous loop, this is a no-op if
1232 REG is contained within SET_DEST (SET). */
1233 mark_ref_live (use
);
1239 extract_insn (insn
);
1240 preferred_alternatives
= get_preferred_alternatives (insn
);
1241 preprocess_constraints (insn
);
1242 process_single_reg_class_operands (false, freq
);
1244 /* See which defined values die here. */
1245 FOR_EACH_INSN_DEF (def
, insn
)
1246 if (!call_p
|| !DF_REF_FLAGS_IS_SET (def
, DF_REF_MAY_CLOBBER
))
1247 mark_ref_dead (def
);
1251 /* Try to find a SET in the CALL_INSN_FUNCTION_USAGE, and from
1252 there, try to find a pseudo that is live across the call but
1253 can be cheaply reconstructed from the return value. */
1254 rtx cheap_reg
= find_call_crossed_cheap_reg (insn
);
1255 if (cheap_reg
!= NULL_RTX
)
1256 add_reg_note (insn
, REG_RETURNED
, cheap_reg
);
1259 sparseset_clear (allocnos_processed
);
1260 /* The current set of live allocnos are live across the call. */
1261 EXECUTE_IF_SET_IN_SPARSESET (objects_live
, i
)
1263 ira_object_t obj
= ira_object_id_map
[i
];
1264 a
= OBJECT_ALLOCNO (obj
);
1265 int num
= ALLOCNO_NUM (a
);
1266 HARD_REG_SET this_call_used_reg_set
;
1268 get_call_reg_set_usage (insn
, &this_call_used_reg_set
,
1271 /* Don't allocate allocnos that cross setjmps or any
1272 call, if this function receives a nonlocal
1274 if (cfun
->has_nonlocal_label
1275 || (!targetm
.setjmp_preserves_nonvolatile_regs_p ()
1276 && (find_reg_note (insn
, REG_SETJMP
, NULL_RTX
)
1279 SET_HARD_REG_SET (OBJECT_CONFLICT_HARD_REGS (obj
));
1280 SET_HARD_REG_SET (OBJECT_TOTAL_CONFLICT_HARD_REGS (obj
));
1282 if (can_throw_internal (insn
))
1284 IOR_HARD_REG_SET (OBJECT_CONFLICT_HARD_REGS (obj
),
1285 this_call_used_reg_set
);
1286 IOR_HARD_REG_SET (OBJECT_TOTAL_CONFLICT_HARD_REGS (obj
),
1287 this_call_used_reg_set
);
1290 if (sparseset_bit_p (allocnos_processed
, num
))
1292 sparseset_set_bit (allocnos_processed
, num
);
1294 if (allocno_saved_at_call
[num
] != last_call_num
)
1295 /* Here we are mimicking caller-save.c behavior
1296 which does not save hard register at a call if
1297 it was saved on previous call in the same basic
1298 block and the hard register was not mentioned
1299 between the two calls. */
1300 ALLOCNO_CALL_FREQ (a
) += freq
;
1301 /* Mark it as saved at the next call. */
1302 allocno_saved_at_call
[num
] = last_call_num
+ 1;
1303 ALLOCNO_CALLS_CROSSED_NUM (a
)++;
1304 IOR_HARD_REG_SET (ALLOCNO_CROSSED_CALLS_CLOBBERED_REGS (a
),
1305 this_call_used_reg_set
);
1306 if (cheap_reg
!= NULL_RTX
1307 && ALLOCNO_REGNO (a
) == (int) REGNO (cheap_reg
))
1308 ALLOCNO_CHEAP_CALLS_CROSSED_NUM (a
)++;
1312 make_early_clobber_and_input_conflicts ();
1316 /* Mark each used value as live. */
1317 FOR_EACH_INSN_USE (use
, insn
)
1318 mark_ref_live (use
);
1320 process_single_reg_class_operands (true, freq
);
1322 set_p
= mark_hard_reg_early_clobbers (insn
, true);
1326 mark_hard_reg_early_clobbers (insn
, false);
1328 /* Mark each hard reg as live again. For example, a
1329 hard register can be in clobber and in an insn
1331 FOR_EACH_INSN_USE (use
, insn
)
1333 rtx ureg
= DF_REF_REG (use
);
1335 if (GET_CODE (ureg
) == SUBREG
)
1336 ureg
= SUBREG_REG (ureg
);
1337 if (! REG_P (ureg
) || REGNO (ureg
) >= FIRST_PSEUDO_REGISTER
)
1340 mark_ref_live (use
);
1346 ignore_reg_for_conflicts
= NULL_RTX
;
1348 if (bb_has_eh_pred (bb
))
1351 unsigned int regno
= EH_RETURN_DATA_REGNO (j
);
1352 if (regno
== INVALID_REGNUM
)
1354 make_hard_regno_live (regno
);
1357 /* Allocnos can't go in stack regs at the start of a basic block
1358 that is reached by an abnormal edge. Likewise for call
1359 clobbered regs, because caller-save, fixup_abnormal_edges and
1360 possibly the table driven EH machinery are not quite ready to
1361 handle such allocnos live across such edges. */
1362 if (bb_has_abnormal_pred (bb
))
1365 EXECUTE_IF_SET_IN_SPARSESET (objects_live
, px
)
1367 ira_allocno_t a
= OBJECT_ALLOCNO (ira_object_id_map
[px
]);
1369 ALLOCNO_NO_STACK_REG_P (a
) = true;
1370 ALLOCNO_TOTAL_NO_STACK_REG_P (a
) = true;
1372 for (px
= FIRST_STACK_REG
; px
<= LAST_STACK_REG
; px
++)
1373 make_hard_regno_live (px
);
1375 /* No need to record conflicts for call clobbered regs if we
1376 have nonlocal labels around, as we don't ever try to
1377 allocate such regs in this case. */
1378 if (!cfun
->has_nonlocal_label
1379 && has_abnormal_call_or_eh_pred_edge_p (bb
))
1380 for (px
= 0; px
< FIRST_PSEUDO_REGISTER
; px
++)
1381 if (call_used_regs
[px
]
1382 #ifdef REAL_PIC_OFFSET_TABLE_REGNUM
1383 /* We should create a conflict of PIC pseudo with
1384 PIC hard reg as PIC hard reg can have a wrong
1385 value after jump described by the abnormal edge.
1386 In this case we cannot allocate PIC hard reg to
1387 PIC pseudo as PIC pseudo will also have a wrong
1388 value. This code is not critical as LRA can fix
1389 it but it is better to have the right allocation
1391 || (px
== REAL_PIC_OFFSET_TABLE_REGNUM
1392 && pic_offset_table_rtx
!= NULL_RTX
1393 && REGNO (pic_offset_table_rtx
) >= FIRST_PSEUDO_REGISTER
)
1396 make_hard_regno_live (px
);
1399 EXECUTE_IF_SET_IN_SPARSESET (objects_live
, i
)
1400 make_object_dead (ira_object_id_map
[i
]);
1405 /* Propagate register pressure to upper loop tree nodes. */
1406 if (loop_tree_node
!= ira_loop_tree_root
)
1407 for (i
= 0; i
< ira_pressure_classes_num
; i
++)
1409 enum reg_class pclass
;
1411 pclass
= ira_pressure_classes
[i
];
1412 if (loop_tree_node
->reg_pressure
[pclass
]
1413 > loop_tree_node
->parent
->reg_pressure
[pclass
])
1414 loop_tree_node
->parent
->reg_pressure
[pclass
]
1415 = loop_tree_node
->reg_pressure
[pclass
];
1419 /* Create and set up IRA_START_POINT_RANGES and
1420 IRA_FINISH_POINT_RANGES. */
1422 create_start_finish_chains (void)
1425 ira_object_iterator oi
;
1428 ira_start_point_ranges
1429 = (live_range_t
*) ira_allocate (ira_max_point
* sizeof (live_range_t
));
1430 memset (ira_start_point_ranges
, 0, ira_max_point
* sizeof (live_range_t
));
1431 ira_finish_point_ranges
1432 = (live_range_t
*) ira_allocate (ira_max_point
* sizeof (live_range_t
));
1433 memset (ira_finish_point_ranges
, 0, ira_max_point
* sizeof (live_range_t
));
1434 FOR_EACH_OBJECT (obj
, oi
)
1435 for (r
= OBJECT_LIVE_RANGES (obj
); r
!= NULL
; r
= r
->next
)
1437 r
->start_next
= ira_start_point_ranges
[r
->start
];
1438 ira_start_point_ranges
[r
->start
] = r
;
1439 r
->finish_next
= ira_finish_point_ranges
[r
->finish
];
1440 ira_finish_point_ranges
[r
->finish
] = r
;
1444 /* Rebuild IRA_START_POINT_RANGES and IRA_FINISH_POINT_RANGES after
1445 new live ranges and program points were added as a result if new
1448 ira_rebuild_start_finish_chains (void)
1450 ira_free (ira_finish_point_ranges
);
1451 ira_free (ira_start_point_ranges
);
1452 create_start_finish_chains ();
1455 /* Compress allocno live ranges by removing program points where
1458 remove_some_program_points_and_update_live_ranges (void)
1464 ira_object_iterator oi
;
1465 live_range_t r
, prev_r
, next_r
;
1466 sbitmap_iterator sbi
;
1467 bool born_p
, dead_p
, prev_born_p
, prev_dead_p
;
1469 auto_sbitmap
born (ira_max_point
);
1470 auto_sbitmap
dead (ira_max_point
);
1471 bitmap_clear (born
);
1472 bitmap_clear (dead
);
1473 FOR_EACH_OBJECT (obj
, oi
)
1474 for (r
= OBJECT_LIVE_RANGES (obj
); r
!= NULL
; r
= r
->next
)
1476 ira_assert (r
->start
<= r
->finish
);
1477 bitmap_set_bit (born
, r
->start
);
1478 bitmap_set_bit (dead
, r
->finish
);
1481 auto_sbitmap
born_or_dead (ira_max_point
);
1482 bitmap_ior (born_or_dead
, born
, dead
);
1483 map
= (int *) ira_allocate (sizeof (int) * ira_max_point
);
1485 prev_born_p
= prev_dead_p
= false;
1486 EXECUTE_IF_SET_IN_BITMAP (born_or_dead
, 0, i
, sbi
)
1488 born_p
= bitmap_bit_p (born
, i
);
1489 dead_p
= bitmap_bit_p (dead
, i
);
1490 if ((prev_born_p
&& ! prev_dead_p
&& born_p
&& ! dead_p
)
1491 || (prev_dead_p
&& ! prev_born_p
&& dead_p
&& ! born_p
))
1495 prev_born_p
= born_p
;
1496 prev_dead_p
= dead_p
;
1500 if (internal_flag_ira_verbose
> 1 && ira_dump_file
!= NULL
)
1501 fprintf (ira_dump_file
, "Compressing live ranges: from %d to %d - %d%%\n",
1502 ira_max_point
, n
, 100 * n
/ ira_max_point
);
1505 FOR_EACH_OBJECT (obj
, oi
)
1506 for (r
= OBJECT_LIVE_RANGES (obj
), prev_r
= NULL
; r
!= NULL
; r
= next_r
)
1509 r
->start
= map
[r
->start
];
1510 r
->finish
= map
[r
->finish
];
1511 if (prev_r
== NULL
|| prev_r
->start
> r
->finish
+ 1)
1516 prev_r
->start
= r
->start
;
1517 prev_r
->next
= next_r
;
1518 ira_finish_live_range (r
);
1524 /* Print live ranges R to file F. */
1526 ira_print_live_range_list (FILE *f
, live_range_t r
)
1528 for (; r
!= NULL
; r
= r
->next
)
1529 fprintf (f
, " [%d..%d]", r
->start
, r
->finish
);
1534 debug (live_range
&ref
)
1536 ira_print_live_range_list (stderr
, &ref
);
1540 debug (live_range
*ptr
)
1545 fprintf (stderr
, "<nil>\n");
1548 /* Print live ranges R to stderr. */
1550 ira_debug_live_range_list (live_range_t r
)
1552 ira_print_live_range_list (stderr
, r
);
1555 /* Print live ranges of object OBJ to file F. */
1557 print_object_live_ranges (FILE *f
, ira_object_t obj
)
1559 ira_print_live_range_list (f
, OBJECT_LIVE_RANGES (obj
));
1562 /* Print live ranges of allocno A to file F. */
1564 print_allocno_live_ranges (FILE *f
, ira_allocno_t a
)
1566 int n
= ALLOCNO_NUM_OBJECTS (a
);
1569 for (i
= 0; i
< n
; i
++)
1571 fprintf (f
, " a%d(r%d", ALLOCNO_NUM (a
), ALLOCNO_REGNO (a
));
1573 fprintf (f
, " [%d]", i
);
1575 print_object_live_ranges (f
, ALLOCNO_OBJECT (a
, i
));
1579 /* Print live ranges of allocno A to stderr. */
1581 ira_debug_allocno_live_ranges (ira_allocno_t a
)
1583 print_allocno_live_ranges (stderr
, a
);
1586 /* Print live ranges of all allocnos to file F. */
1588 print_live_ranges (FILE *f
)
1591 ira_allocno_iterator ai
;
1593 FOR_EACH_ALLOCNO (a
, ai
)
1594 print_allocno_live_ranges (f
, a
);
1597 /* Print live ranges of all allocnos to stderr. */
1599 ira_debug_live_ranges (void)
1601 print_live_ranges (stderr
);
1604 /* The main entry function creates live ranges, set up
1605 CONFLICT_HARD_REGS and TOTAL_CONFLICT_HARD_REGS for objects, and
1606 calculate register pressure info. */
1608 ira_create_allocno_live_ranges (void)
1610 objects_live
= sparseset_alloc (ira_objects_num
);
1611 allocnos_processed
= sparseset_alloc (ira_allocnos_num
);
1614 allocno_saved_at_call
1615 = (int *) ira_allocate (ira_allocnos_num
* sizeof (int));
1616 memset (allocno_saved_at_call
, 0, ira_allocnos_num
* sizeof (int));
1617 ira_traverse_loop_tree (true, ira_loop_tree_root
, NULL
,
1618 process_bb_node_lives
);
1619 ira_max_point
= curr_point
;
1620 create_start_finish_chains ();
1621 if (internal_flag_ira_verbose
> 2 && ira_dump_file
!= NULL
)
1622 print_live_ranges (ira_dump_file
);
1624 ira_free (allocno_saved_at_call
);
1625 sparseset_free (objects_live
);
1626 sparseset_free (allocnos_processed
);
1629 /* Compress allocno live ranges. */
1631 ira_compress_allocno_live_ranges (void)
1633 remove_some_program_points_and_update_live_ranges ();
1634 ira_rebuild_start_finish_chains ();
1635 if (internal_flag_ira_verbose
> 2 && ira_dump_file
!= NULL
)
1637 fprintf (ira_dump_file
, "Ranges after the compression:\n");
1638 print_live_ranges (ira_dump_file
);
1642 /* Free arrays IRA_START_POINT_RANGES and IRA_FINISH_POINT_RANGES. */
1644 ira_finish_allocno_live_ranges (void)
1646 ira_free (ira_finish_point_ranges
);
1647 ira_free (ira_start_point_ranges
);