* sv.po: Update.
[official-gcc.git] / gcc / ira-lives.c
blob8a255c22f2118bc4fff805bbd06d3d3817cc4a4b
1 /* IRA processing allocno lives to build allocno live ranges.
2 Copyright (C) 2006, 2007, 2008, 2009, 2010
3 Free Software Foundation, Inc.
4 Contributed by Vladimir Makarov <vmakarov@redhat.com>.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
11 version.
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tm.h"
26 #include "regs.h"
27 #include "rtl.h"
28 #include "tm_p.h"
29 #include "target.h"
30 #include "flags.h"
31 #include "except.h"
32 #include "hard-reg-set.h"
33 #include "basic-block.h"
34 #include "insn-config.h"
35 #include "recog.h"
36 #include "diagnostic-core.h"
37 #include "toplev.h"
38 #include "params.h"
39 #include "df.h"
40 #include "sbitmap.h"
41 #include "sparseset.h"
42 #include "ira-int.h"
44 /* The code in this file is similar to one in global but the code
45 works on the allocno basis and creates live ranges instead of
46 pseudo-register conflicts. */
48 /* Program points are enumerated by numbers from range
49 0..IRA_MAX_POINT-1. There are approximately two times more program
50 points than insns. Program points are places in the program where
51 liveness info can be changed. In most general case (there are more
52 complicated cases too) some program points correspond to places
53 where input operand dies and other ones correspond to places where
54 output operands are born. */
55 int ira_max_point;
57 /* Arrays of size IRA_MAX_POINT mapping a program point to the allocno
58 live ranges with given start/finish point. */
59 live_range_t *ira_start_point_ranges, *ira_finish_point_ranges;
61 /* Number of the current program point. */
62 static int curr_point;
64 /* Point where register pressure excess started or -1 if there is no
65 register pressure excess. Excess pressure for a register class at
66 some point means that there are more allocnos of given register
67 class living at the point than number of hard-registers of the
68 class available for the allocation. It is defined only for cover
69 classes. */
70 static int high_pressure_start_point[N_REG_CLASSES];
72 /* Objects live at current point in the scan. */
73 static sparseset objects_live;
75 /* A temporary bitmap used in functions that wish to avoid visiting an allocno
76 multiple times. */
77 static sparseset allocnos_processed;
79 /* Set of hard regs (except eliminable ones) currently live. */
80 static HARD_REG_SET hard_regs_live;
82 /* The loop tree node corresponding to the current basic block. */
83 static ira_loop_tree_node_t curr_bb_node;
85 /* The number of the last processed call. */
86 static int last_call_num;
87 /* The number of last call at which given allocno was saved. */
88 static int *allocno_saved_at_call;
90 /* Record the birth of hard register REGNO, updating hard_regs_live and
91 hard reg conflict information for living allocnos. */
92 static void
93 make_hard_regno_born (int regno)
95 unsigned int i;
97 SET_HARD_REG_BIT (hard_regs_live, regno);
98 EXECUTE_IF_SET_IN_SPARSESET (objects_live, i)
100 ira_object_t obj = ira_object_id_map[i];
101 SET_HARD_REG_BIT (OBJECT_CONFLICT_HARD_REGS (obj), regno);
102 SET_HARD_REG_BIT (OBJECT_TOTAL_CONFLICT_HARD_REGS (obj), regno);
106 /* Process the death of hard register REGNO. This updates
107 hard_regs_live. */
108 static void
109 make_hard_regno_dead (int regno)
111 CLEAR_HARD_REG_BIT (hard_regs_live, regno);
114 /* Record the birth of object OBJ. Set a bit for it in objects_live,
115 start a new live range for it if necessary and update hard register
116 conflicts. */
117 static void
118 make_object_born (ira_object_t obj)
120 live_range_t lr = OBJECT_LIVE_RANGES (obj);
122 sparseset_set_bit (objects_live, OBJECT_CONFLICT_ID (obj));
123 IOR_HARD_REG_SET (OBJECT_CONFLICT_HARD_REGS (obj), hard_regs_live);
124 IOR_HARD_REG_SET (OBJECT_TOTAL_CONFLICT_HARD_REGS (obj), hard_regs_live);
126 if (lr == NULL
127 || (lr->finish != curr_point && lr->finish + 1 != curr_point))
128 ira_add_live_range_to_object (obj, curr_point, -1);
131 /* Update ALLOCNO_EXCESS_PRESSURE_POINTS_NUM for the allocno
132 associated with object OBJ. */
133 static void
134 update_allocno_pressure_excess_length (ira_object_t obj)
136 ira_allocno_t a = OBJECT_ALLOCNO (obj);
137 int start, i;
138 enum reg_class cover_class, cl;
139 live_range_t p;
141 cover_class = ALLOCNO_COVER_CLASS (a);
142 for (i = 0;
143 (cl = ira_reg_class_super_classes[cover_class][i]) != LIM_REG_CLASSES;
144 i++)
146 if (high_pressure_start_point[cl] < 0)
147 continue;
148 p = OBJECT_LIVE_RANGES (obj);
149 ira_assert (p != NULL);
150 start = (high_pressure_start_point[cl] > p->start
151 ? high_pressure_start_point[cl] : p->start);
152 ALLOCNO_EXCESS_PRESSURE_POINTS_NUM (a) += curr_point - start + 1;
156 /* Process the death of object OBJ, which is associated with allocno
157 A. This finishes the current live range for it. */
158 static void
159 make_object_dead (ira_object_t obj)
161 live_range_t lr;
163 sparseset_clear_bit (objects_live, OBJECT_CONFLICT_ID (obj));
164 lr = OBJECT_LIVE_RANGES (obj);
165 ira_assert (lr != NULL);
166 lr->finish = curr_point;
167 update_allocno_pressure_excess_length (obj);
170 /* The current register pressures for each cover class for the current
171 basic block. */
172 static int curr_reg_pressure[N_REG_CLASSES];
174 /* Record that register pressure for COVER_CLASS increased by N
175 registers. Update the current register pressure, maximal register
176 pressure for the current BB and the start point of the register
177 pressure excess. */
178 static void
179 inc_register_pressure (enum reg_class cover_class, int n)
181 int i;
182 enum reg_class cl;
184 for (i = 0;
185 (cl = ira_reg_class_super_classes[cover_class][i]) != LIM_REG_CLASSES;
186 i++)
188 curr_reg_pressure[cl] += n;
189 if (high_pressure_start_point[cl] < 0
190 && (curr_reg_pressure[cl] > ira_available_class_regs[cl]))
191 high_pressure_start_point[cl] = curr_point;
192 if (curr_bb_node->reg_pressure[cl] < curr_reg_pressure[cl])
193 curr_bb_node->reg_pressure[cl] = curr_reg_pressure[cl];
197 /* Record that register pressure for COVER_CLASS has decreased by
198 NREGS registers; update current register pressure, start point of
199 the register pressure excess, and register pressure excess length
200 for living allocnos. */
202 static void
203 dec_register_pressure (enum reg_class cover_class, int nregs)
205 int i;
206 unsigned int j;
207 enum reg_class cl;
208 bool set_p = false;
210 for (i = 0;
211 (cl = ira_reg_class_super_classes[cover_class][i]) != LIM_REG_CLASSES;
212 i++)
214 curr_reg_pressure[cl] -= nregs;
215 ira_assert (curr_reg_pressure[cl] >= 0);
216 if (high_pressure_start_point[cl] >= 0
217 && curr_reg_pressure[cl] <= ira_available_class_regs[cl])
218 set_p = true;
220 if (set_p)
222 EXECUTE_IF_SET_IN_SPARSESET (objects_live, j)
223 update_allocno_pressure_excess_length (ira_object_id_map[j]);
224 for (i = 0;
225 (cl = ira_reg_class_super_classes[cover_class][i])
226 != LIM_REG_CLASSES;
227 i++)
228 if (high_pressure_start_point[cl] >= 0
229 && curr_reg_pressure[cl] <= ira_available_class_regs[cl])
230 high_pressure_start_point[cl] = -1;
234 /* Mark the pseudo register REGNO as live. Update all information about
235 live ranges and register pressure. */
236 static void
237 mark_pseudo_regno_live (int regno)
239 ira_allocno_t a = ira_curr_regno_allocno_map[regno];
240 int i, n, nregs;
241 enum reg_class cl;
243 if (a == NULL)
244 return;
246 /* Invalidate because it is referenced. */
247 allocno_saved_at_call[ALLOCNO_NUM (a)] = 0;
249 n = ALLOCNO_NUM_OBJECTS (a);
250 cl = ALLOCNO_COVER_CLASS (a);
251 nregs = ira_reg_class_nregs[cl][ALLOCNO_MODE (a)];
252 if (n > 1)
254 /* We track every subobject separately. */
255 gcc_assert (nregs == n);
256 nregs = 1;
259 for (i = 0; i < n; i++)
261 ira_object_t obj = ALLOCNO_OBJECT (a, i);
262 if (sparseset_bit_p (objects_live, OBJECT_CONFLICT_ID (obj)))
263 continue;
265 inc_register_pressure (cl, nregs);
266 make_object_born (obj);
270 /* Like mark_pseudo_regno_live, but try to only mark one subword of
271 the pseudo as live. SUBWORD indicates which; a value of 0
272 indicates the low part. */
273 static void
274 mark_pseudo_regno_subword_live (int regno, int subword)
276 ira_allocno_t a = ira_curr_regno_allocno_map[regno];
277 int n, nregs;
278 enum reg_class cl;
279 ira_object_t obj;
281 if (a == NULL)
282 return;
284 /* Invalidate because it is referenced. */
285 allocno_saved_at_call[ALLOCNO_NUM (a)] = 0;
287 n = ALLOCNO_NUM_OBJECTS (a);
288 if (n == 1)
290 mark_pseudo_regno_live (regno);
291 return;
294 cl = ALLOCNO_COVER_CLASS (a);
295 nregs = ira_reg_class_nregs[cl][ALLOCNO_MODE (a)];
296 gcc_assert (nregs == n);
297 obj = ALLOCNO_OBJECT (a, subword);
299 if (sparseset_bit_p (objects_live, OBJECT_CONFLICT_ID (obj)))
300 return;
302 inc_register_pressure (cl, nregs);
303 make_object_born (obj);
306 /* Mark the register REG as live. Store a 1 in hard_regs_live for
307 this register, record how many consecutive hardware registers it
308 actually needs. */
309 static void
310 mark_hard_reg_live (rtx reg)
312 int regno = REGNO (reg);
314 if (! TEST_HARD_REG_BIT (ira_no_alloc_regs, regno))
316 int last = regno + hard_regno_nregs[regno][GET_MODE (reg)];
318 while (regno < last)
320 if (! TEST_HARD_REG_BIT (hard_regs_live, regno)
321 && ! TEST_HARD_REG_BIT (eliminable_regset, regno))
323 enum reg_class cover_class = ira_hard_regno_cover_class[regno];
324 inc_register_pressure (cover_class, 1);
325 make_hard_regno_born (regno);
327 regno++;
332 /* Mark a pseudo, or one of its subwords, as live. REGNO is the pseudo's
333 register number; ORIG_REG is the access in the insn, which may be a
334 subreg. */
335 static void
336 mark_pseudo_reg_live (rtx orig_reg, unsigned regno)
338 if (df_read_modify_subreg_p (orig_reg))
340 mark_pseudo_regno_subword_live (regno,
341 subreg_lowpart_p (orig_reg) ? 0 : 1);
343 else
344 mark_pseudo_regno_live (regno);
347 /* Mark the register referenced by use or def REF as live. */
348 static void
349 mark_ref_live (df_ref ref)
351 rtx reg = DF_REF_REG (ref);
352 rtx orig_reg = reg;
354 if (GET_CODE (reg) == SUBREG)
355 reg = SUBREG_REG (reg);
357 if (REGNO (reg) >= FIRST_PSEUDO_REGISTER)
358 mark_pseudo_reg_live (orig_reg, REGNO (reg));
359 else
360 mark_hard_reg_live (reg);
363 /* Mark the pseudo register REGNO as dead. Update all information about
364 live ranges and register pressure. */
365 static void
366 mark_pseudo_regno_dead (int regno)
368 ira_allocno_t a = ira_curr_regno_allocno_map[regno];
369 int n, i, nregs;
370 enum reg_class cl;
372 if (a == NULL)
373 return;
375 /* Invalidate because it is referenced. */
376 allocno_saved_at_call[ALLOCNO_NUM (a)] = 0;
378 n = ALLOCNO_NUM_OBJECTS (a);
379 cl = ALLOCNO_COVER_CLASS (a);
380 nregs = ira_reg_class_nregs[cl][ALLOCNO_MODE (a)];
381 if (n > 1)
383 /* We track every subobject separately. */
384 gcc_assert (nregs == n);
385 nregs = 1;
387 for (i = 0; i < n; i++)
389 ira_object_t obj = ALLOCNO_OBJECT (a, i);
390 if (!sparseset_bit_p (objects_live, OBJECT_CONFLICT_ID (obj)))
391 continue;
393 dec_register_pressure (cl, nregs);
394 make_object_dead (obj);
398 /* Like mark_pseudo_regno_dead, but called when we know that only part of the
399 register dies. SUBWORD indicates which; a value of 0 indicates the low part. */
400 static void
401 mark_pseudo_regno_subword_dead (int regno, int subword)
403 ira_allocno_t a = ira_curr_regno_allocno_map[regno];
404 int n, nregs;
405 enum reg_class cl;
406 ira_object_t obj;
408 if (a == NULL)
409 return;
411 /* Invalidate because it is referenced. */
412 allocno_saved_at_call[ALLOCNO_NUM (a)] = 0;
414 n = ALLOCNO_NUM_OBJECTS (a);
415 if (n == 1)
416 /* The allocno as a whole doesn't die in this case. */
417 return;
419 cl = ALLOCNO_COVER_CLASS (a);
420 nregs = ira_reg_class_nregs[cl][ALLOCNO_MODE (a)];
421 gcc_assert (nregs == n);
423 obj = ALLOCNO_OBJECT (a, subword);
424 if (!sparseset_bit_p (objects_live, OBJECT_CONFLICT_ID (obj)))
425 return;
427 dec_register_pressure (cl, 1);
428 make_object_dead (obj);
431 /* Mark the hard register REG as dead. Store a 0 in hard_regs_live for the
432 register. */
433 static void
434 mark_hard_reg_dead (rtx reg)
436 int regno = REGNO (reg);
438 if (! TEST_HARD_REG_BIT (ira_no_alloc_regs, regno))
440 int last = regno + hard_regno_nregs[regno][GET_MODE (reg)];
442 while (regno < last)
444 if (TEST_HARD_REG_BIT (hard_regs_live, regno))
446 enum reg_class cover_class = ira_hard_regno_cover_class[regno];
447 dec_register_pressure (cover_class, 1);
448 make_hard_regno_dead (regno);
450 regno++;
455 /* Mark a pseudo, or one of its subwords, as dead. REGNO is the pseudo's
456 register number; ORIG_REG is the access in the insn, which may be a
457 subreg. */
458 static void
459 mark_pseudo_reg_dead (rtx orig_reg, unsigned regno)
461 if (df_read_modify_subreg_p (orig_reg))
463 mark_pseudo_regno_subword_dead (regno,
464 subreg_lowpart_p (orig_reg) ? 0 : 1);
466 else
467 mark_pseudo_regno_dead (regno);
470 /* Mark the register referenced by definition DEF as dead, if the
471 definition is a total one. */
472 static void
473 mark_ref_dead (df_ref def)
475 rtx reg = DF_REF_REG (def);
476 rtx orig_reg = reg;
478 if (DF_REF_FLAGS_IS_SET (def, DF_REF_CONDITIONAL))
479 return;
481 if (GET_CODE (reg) == SUBREG)
482 reg = SUBREG_REG (reg);
484 if (DF_REF_FLAGS_IS_SET (def, DF_REF_PARTIAL)
485 && (GET_CODE (orig_reg) != SUBREG
486 || REGNO (reg) < FIRST_PSEUDO_REGISTER
487 || !df_read_modify_subreg_p (orig_reg)))
488 return;
490 if (REGNO (reg) >= FIRST_PSEUDO_REGISTER)
491 mark_pseudo_reg_dead (orig_reg, REGNO (reg));
492 else
493 mark_hard_reg_dead (reg);
496 /* If REG is a pseudo or a subreg of it, and the class of its allocno
497 intersects CL, make a conflict with pseudo DREG. ORIG_DREG is the
498 rtx actually accessed, it may be indentical to DREG or a subreg of it.
499 Advance the current program point before making the conflict if
500 ADVANCE_P. Return TRUE if we will need to advance the current
501 program point. */
502 static bool
503 make_pseudo_conflict (rtx reg, enum reg_class cl, rtx dreg, rtx orig_dreg,
504 bool advance_p)
506 rtx orig_reg = reg;
507 ira_allocno_t a;
509 if (GET_CODE (reg) == SUBREG)
510 reg = SUBREG_REG (reg);
512 if (! REG_P (reg) || REGNO (reg) < FIRST_PSEUDO_REGISTER)
513 return advance_p;
515 a = ira_curr_regno_allocno_map[REGNO (reg)];
516 if (! reg_classes_intersect_p (cl, ALLOCNO_COVER_CLASS (a)))
517 return advance_p;
519 if (advance_p)
520 curr_point++;
522 mark_pseudo_reg_live (orig_reg, REGNO (reg));
523 mark_pseudo_reg_live (orig_dreg, REGNO (dreg));
524 mark_pseudo_reg_dead (orig_reg, REGNO (reg));
525 mark_pseudo_reg_dead (orig_dreg, REGNO (dreg));
527 return false;
530 /* Check and make if necessary conflicts for pseudo DREG of class
531 DEF_CL of the current insn with input operand USE of class USE_CL.
532 ORIG_DREG is the rtx actually accessed, it may be indentical to
533 DREG or a subreg of it. Advance the current program point before
534 making the conflict if ADVANCE_P. Return TRUE if we will need to
535 advance the current program point. */
536 static bool
537 check_and_make_def_use_conflict (rtx dreg, rtx orig_dreg,
538 enum reg_class def_cl, int use,
539 enum reg_class use_cl, bool advance_p)
541 if (! reg_classes_intersect_p (def_cl, use_cl))
542 return advance_p;
544 advance_p = make_pseudo_conflict (recog_data.operand[use],
545 use_cl, dreg, orig_dreg, advance_p);
547 /* Reload may end up swapping commutative operands, so you
548 have to take both orderings into account. The
549 constraints for the two operands can be completely
550 different. (Indeed, if the constraints for the two
551 operands are the same for all alternatives, there's no
552 point marking them as commutative.) */
553 if (use < recog_data.n_operands - 1
554 && recog_data.constraints[use][0] == '%')
555 advance_p
556 = make_pseudo_conflict (recog_data.operand[use + 1],
557 use_cl, dreg, orig_dreg, advance_p);
558 if (use >= 1
559 && recog_data.constraints[use - 1][0] == '%')
560 advance_p
561 = make_pseudo_conflict (recog_data.operand[use - 1],
562 use_cl, dreg, orig_dreg, advance_p);
563 return advance_p;
566 /* Check and make if necessary conflicts for definition DEF of class
567 DEF_CL of the current insn with input operands. Process only
568 constraints of alternative ALT. */
569 static void
570 check_and_make_def_conflict (int alt, int def, enum reg_class def_cl)
572 int use, use_match;
573 ira_allocno_t a;
574 enum reg_class use_cl, acl;
575 bool advance_p;
576 rtx dreg = recog_data.operand[def];
577 rtx orig_dreg = dreg;
579 if (def_cl == NO_REGS)
580 return;
582 if (GET_CODE (dreg) == SUBREG)
583 dreg = SUBREG_REG (dreg);
585 if (! REG_P (dreg) || REGNO (dreg) < FIRST_PSEUDO_REGISTER)
586 return;
588 a = ira_curr_regno_allocno_map[REGNO (dreg)];
589 acl = ALLOCNO_COVER_CLASS (a);
590 if (! reg_classes_intersect_p (acl, def_cl))
591 return;
593 advance_p = true;
595 for (use = 0; use < recog_data.n_operands; use++)
597 int alt1;
599 if (use == def || recog_data.operand_type[use] == OP_OUT)
600 continue;
602 if (recog_op_alt[use][alt].anything_ok)
603 use_cl = ALL_REGS;
604 else
605 use_cl = recog_op_alt[use][alt].cl;
607 /* If there's any alternative that allows USE to match DEF, do not
608 record a conflict. If that causes us to create an invalid
609 instruction due to the earlyclobber, reload must fix it up. */
610 for (alt1 = 0; alt1 < recog_data.n_alternatives; alt1++)
611 if (recog_op_alt[use][alt1].matches == def
612 || (use < recog_data.n_operands - 1
613 && recog_data.constraints[use][0] == '%'
614 && recog_op_alt[use + 1][alt1].matches == def)
615 || (use >= 1
616 && recog_data.constraints[use - 1][0] == '%'
617 && recog_op_alt[use - 1][alt1].matches == def))
618 break;
620 if (alt1 < recog_data.n_alternatives)
621 continue;
623 advance_p = check_and_make_def_use_conflict (dreg, orig_dreg, def_cl,
624 use, use_cl, advance_p);
626 if ((use_match = recog_op_alt[use][alt].matches) >= 0)
628 if (use_match == def)
629 continue;
631 if (recog_op_alt[use_match][alt].anything_ok)
632 use_cl = ALL_REGS;
633 else
634 use_cl = recog_op_alt[use_match][alt].cl;
635 advance_p = check_and_make_def_use_conflict (dreg, orig_dreg, def_cl,
636 use, use_cl, advance_p);
641 /* Make conflicts of early clobber pseudo registers of the current
642 insn with its inputs. Avoid introducing unnecessary conflicts by
643 checking classes of the constraints and pseudos because otherwise
644 significant code degradation is possible for some targets. */
645 static void
646 make_early_clobber_and_input_conflicts (void)
648 int alt;
649 int def, def_match;
650 enum reg_class def_cl;
652 for (alt = 0; alt < recog_data.n_alternatives; alt++)
653 for (def = 0; def < recog_data.n_operands; def++)
655 def_cl = NO_REGS;
656 if (recog_op_alt[def][alt].earlyclobber)
658 if (recog_op_alt[def][alt].anything_ok)
659 def_cl = ALL_REGS;
660 else
661 def_cl = recog_op_alt[def][alt].cl;
662 check_and_make_def_conflict (alt, def, def_cl);
664 if ((def_match = recog_op_alt[def][alt].matches) >= 0
665 && (recog_op_alt[def_match][alt].earlyclobber
666 || recog_op_alt[def][alt].earlyclobber))
668 if (recog_op_alt[def_match][alt].anything_ok)
669 def_cl = ALL_REGS;
670 else
671 def_cl = recog_op_alt[def_match][alt].cl;
672 check_and_make_def_conflict (alt, def, def_cl);
677 /* Mark early clobber hard registers of the current INSN as live (if
678 LIVE_P) or dead. Return true if there are such registers. */
679 static bool
680 mark_hard_reg_early_clobbers (rtx insn, bool live_p)
682 df_ref *def_rec;
683 bool set_p = false;
685 for (def_rec = DF_INSN_DEFS (insn); *def_rec; def_rec++)
686 if (DF_REF_FLAGS_IS_SET (*def_rec, DF_REF_MUST_CLOBBER))
688 rtx dreg = DF_REF_REG (*def_rec);
690 if (GET_CODE (dreg) == SUBREG)
691 dreg = SUBREG_REG (dreg);
692 if (! REG_P (dreg) || REGNO (dreg) >= FIRST_PSEUDO_REGISTER)
693 continue;
695 /* Hard register clobbers are believed to be early clobber
696 because there is no way to say that non-operand hard
697 register clobbers are not early ones. */
698 if (live_p)
699 mark_ref_live (*def_rec);
700 else
701 mark_ref_dead (*def_rec);
702 set_p = true;
705 return set_p;
708 /* Checks that CONSTRAINTS permits to use only one hard register. If
709 it is so, the function returns the class of the hard register.
710 Otherwise it returns NO_REGS. */
711 static enum reg_class
712 single_reg_class (const char *constraints, rtx op, rtx equiv_const)
714 int ignore_p;
715 enum reg_class cl, next_cl;
716 int c;
718 cl = NO_REGS;
719 for (ignore_p = false;
720 (c = *constraints);
721 constraints += CONSTRAINT_LEN (c, constraints))
722 if (c == '#')
723 ignore_p = true;
724 else if (c == ',')
725 ignore_p = false;
726 else if (! ignore_p)
727 switch (c)
729 case ' ':
730 case '\t':
731 case '=':
732 case '+':
733 case '*':
734 case '&':
735 case '%':
736 case '!':
737 case '?':
738 break;
739 case 'i':
740 if (CONSTANT_P (op)
741 || (equiv_const != NULL_RTX && CONSTANT_P (equiv_const)))
742 return NO_REGS;
743 break;
745 case 'n':
746 if (CONST_INT_P (op)
747 || (GET_CODE (op) == CONST_DOUBLE && GET_MODE (op) == VOIDmode)
748 || (equiv_const != NULL_RTX
749 && (CONST_INT_P (equiv_const)
750 || (GET_CODE (equiv_const) == CONST_DOUBLE
751 && GET_MODE (equiv_const) == VOIDmode))))
752 return NO_REGS;
753 break;
755 case 's':
756 if ((CONSTANT_P (op) && !CONST_INT_P (op)
757 && (GET_CODE (op) != CONST_DOUBLE || GET_MODE (op) != VOIDmode))
758 || (equiv_const != NULL_RTX
759 && CONSTANT_P (equiv_const)
760 && !CONST_INT_P (equiv_const)
761 && (GET_CODE (equiv_const) != CONST_DOUBLE
762 || GET_MODE (equiv_const) != VOIDmode)))
763 return NO_REGS;
764 break;
766 case 'I':
767 case 'J':
768 case 'K':
769 case 'L':
770 case 'M':
771 case 'N':
772 case 'O':
773 case 'P':
774 if ((CONST_INT_P (op)
775 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op), c, constraints))
776 || (equiv_const != NULL_RTX
777 && CONST_INT_P (equiv_const)
778 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (equiv_const),
779 c, constraints)))
780 return NO_REGS;
781 break;
783 case 'E':
784 case 'F':
785 if (GET_CODE (op) == CONST_DOUBLE
786 || (GET_CODE (op) == CONST_VECTOR
787 && GET_MODE_CLASS (GET_MODE (op)) == MODE_VECTOR_FLOAT)
788 || (equiv_const != NULL_RTX
789 && (GET_CODE (equiv_const) == CONST_DOUBLE
790 || (GET_CODE (equiv_const) == CONST_VECTOR
791 && (GET_MODE_CLASS (GET_MODE (equiv_const))
792 == MODE_VECTOR_FLOAT)))))
793 return NO_REGS;
794 break;
796 case 'G':
797 case 'H':
798 if ((GET_CODE (op) == CONST_DOUBLE
799 && CONST_DOUBLE_OK_FOR_CONSTRAINT_P (op, c, constraints))
800 || (equiv_const != NULL_RTX
801 && GET_CODE (equiv_const) == CONST_DOUBLE
802 && CONST_DOUBLE_OK_FOR_CONSTRAINT_P (equiv_const,
803 c, constraints)))
804 return NO_REGS;
805 /* ??? what about memory */
806 case 'r':
807 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
808 case 'h': case 'j': case 'k': case 'l':
809 case 'q': case 't': case 'u':
810 case 'v': case 'w': case 'x': case 'y': case 'z':
811 case 'A': case 'B': case 'C': case 'D':
812 case 'Q': case 'R': case 'S': case 'T': case 'U':
813 case 'W': case 'Y': case 'Z':
814 next_cl = (c == 'r'
815 ? GENERAL_REGS
816 : REG_CLASS_FROM_CONSTRAINT (c, constraints));
817 if ((cl != NO_REGS && next_cl != cl)
818 || (ira_available_class_regs[next_cl]
819 > ira_reg_class_nregs[next_cl][GET_MODE (op)]))
820 return NO_REGS;
821 cl = next_cl;
822 break;
824 case '0': case '1': case '2': case '3': case '4':
825 case '5': case '6': case '7': case '8': case '9':
826 next_cl
827 = single_reg_class (recog_data.constraints[c - '0'],
828 recog_data.operand[c - '0'], NULL_RTX);
829 if ((cl != NO_REGS && next_cl != cl)
830 || next_cl == NO_REGS
831 || (ira_available_class_regs[next_cl]
832 > ira_reg_class_nregs[next_cl][GET_MODE (op)]))
833 return NO_REGS;
834 cl = next_cl;
835 break;
837 default:
838 return NO_REGS;
840 return cl;
843 /* The function checks that operand OP_NUM of the current insn can use
844 only one hard register. If it is so, the function returns the
845 class of the hard register. Otherwise it returns NO_REGS. */
846 static enum reg_class
847 single_reg_operand_class (int op_num)
849 if (op_num < 0 || recog_data.n_alternatives == 0)
850 return NO_REGS;
851 return single_reg_class (recog_data.constraints[op_num],
852 recog_data.operand[op_num], NULL_RTX);
855 /* The function sets up hard register set *SET to hard registers which
856 might be used by insn reloads because the constraints are too
857 strict. */
858 void
859 ira_implicitly_set_insn_hard_regs (HARD_REG_SET *set)
861 int i, c, regno = 0;
862 bool ignore_p;
863 enum reg_class cl;
864 rtx op;
865 enum machine_mode mode;
867 CLEAR_HARD_REG_SET (*set);
868 for (i = 0; i < recog_data.n_operands; i++)
870 op = recog_data.operand[i];
872 if (GET_CODE (op) == SUBREG)
873 op = SUBREG_REG (op);
875 if (GET_CODE (op) == SCRATCH
876 || (REG_P (op) && (regno = REGNO (op)) >= FIRST_PSEUDO_REGISTER))
878 const char *p = recog_data.constraints[i];
880 mode = (GET_CODE (op) == SCRATCH
881 ? GET_MODE (op) : PSEUDO_REGNO_MODE (regno));
882 cl = NO_REGS;
883 for (ignore_p = false; (c = *p); p += CONSTRAINT_LEN (c, p))
884 if (c == '#')
885 ignore_p = true;
886 else if (c == ',')
887 ignore_p = false;
888 else if (! ignore_p)
889 switch (c)
891 case 'r':
892 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
893 case 'h': case 'j': case 'k': case 'l':
894 case 'q': case 't': case 'u':
895 case 'v': case 'w': case 'x': case 'y': case 'z':
896 case 'A': case 'B': case 'C': case 'D':
897 case 'Q': case 'R': case 'S': case 'T': case 'U':
898 case 'W': case 'Y': case 'Z':
899 cl = (c == 'r'
900 ? GENERAL_REGS
901 : REG_CLASS_FROM_CONSTRAINT (c, p));
902 if (cl != NO_REGS
903 /* There is no register pressure problem if all of the
904 regs in this class are fixed. */
905 && ira_available_class_regs[cl] != 0
906 && (ira_available_class_regs[cl]
907 <= ira_reg_class_nregs[cl][mode]))
908 IOR_HARD_REG_SET (*set, reg_class_contents[cl]);
909 break;
914 /* Processes input operands, if IN_P, or output operands otherwise of
915 the current insn with FREQ to find allocno which can use only one
916 hard register and makes other currently living allocnos conflicting
917 with the hard register. */
918 static void
919 process_single_reg_class_operands (bool in_p, int freq)
921 int i, regno;
922 unsigned int px;
923 enum reg_class cl;
924 rtx operand;
925 ira_allocno_t operand_a, a;
927 for (i = 0; i < recog_data.n_operands; i++)
929 operand = recog_data.operand[i];
930 if (in_p && recog_data.operand_type[i] != OP_IN
931 && recog_data.operand_type[i] != OP_INOUT)
932 continue;
933 if (! in_p && recog_data.operand_type[i] != OP_OUT
934 && recog_data.operand_type[i] != OP_INOUT)
935 continue;
936 cl = single_reg_operand_class (i);
937 if (cl == NO_REGS)
938 continue;
940 operand_a = NULL;
942 if (GET_CODE (operand) == SUBREG)
943 operand = SUBREG_REG (operand);
945 if (REG_P (operand)
946 && (regno = REGNO (operand)) >= FIRST_PSEUDO_REGISTER)
948 enum reg_class cover_class;
950 operand_a = ira_curr_regno_allocno_map[regno];
951 cover_class = ALLOCNO_COVER_CLASS (operand_a);
952 if (ira_class_subset_p[cl][cover_class]
953 && ira_class_hard_regs_num[cl] != 0)
955 /* View the desired allocation of OPERAND as:
957 (REG:YMODE YREGNO),
959 a simplification of:
961 (subreg:YMODE (reg:XMODE XREGNO) OFFSET). */
962 enum machine_mode ymode, xmode;
963 int xregno, yregno;
964 HOST_WIDE_INT offset;
966 xmode = recog_data.operand_mode[i];
967 xregno = ira_class_hard_regs[cl][0];
968 ymode = ALLOCNO_MODE (operand_a);
969 offset = subreg_lowpart_offset (ymode, xmode);
970 yregno = simplify_subreg_regno (xregno, xmode, offset, ymode);
971 if (yregno >= 0
972 && ira_class_hard_reg_index[cover_class][yregno] >= 0)
974 int cost;
976 ira_allocate_and_set_costs
977 (&ALLOCNO_CONFLICT_HARD_REG_COSTS (operand_a),
978 cover_class, 0);
979 cost
980 = (freq
981 * (in_p
982 ? ira_get_register_move_cost (xmode, cover_class, cl)
983 : ira_get_register_move_cost (xmode, cl,
984 cover_class)));
985 ALLOCNO_CONFLICT_HARD_REG_COSTS (operand_a)
986 [ira_class_hard_reg_index[cover_class][yregno]] -= cost;
991 EXECUTE_IF_SET_IN_SPARSESET (objects_live, px)
993 ira_object_t obj = ira_object_id_map[px];
994 a = OBJECT_ALLOCNO (obj);
995 if (a != operand_a)
997 /* We could increase costs of A instead of making it
998 conflicting with the hard register. But it works worse
999 because it will be spilled in reload in anyway. */
1000 IOR_HARD_REG_SET (OBJECT_CONFLICT_HARD_REGS (obj),
1001 reg_class_contents[cl]);
1002 IOR_HARD_REG_SET (OBJECT_TOTAL_CONFLICT_HARD_REGS (obj),
1003 reg_class_contents[cl]);
1009 /* Return true when one of the predecessor edges of BB is marked with
1010 EDGE_ABNORMAL_CALL or EDGE_EH. */
1011 static bool
1012 bb_has_abnormal_call_pred (basic_block bb)
1014 edge e;
1015 edge_iterator ei;
1017 FOR_EACH_EDGE (e, ei, bb->preds)
1019 if (e->flags & (EDGE_ABNORMAL_CALL | EDGE_EH))
1020 return true;
1022 return false;
1025 /* Process insns of the basic block given by its LOOP_TREE_NODE to
1026 update allocno live ranges, allocno hard register conflicts,
1027 intersected calls, and register pressure info for allocnos for the
1028 basic block for and regions containing the basic block. */
1029 static void
1030 process_bb_node_lives (ira_loop_tree_node_t loop_tree_node)
1032 int i, freq;
1033 unsigned int j;
1034 basic_block bb;
1035 rtx insn;
1036 bitmap_iterator bi;
1037 bitmap reg_live_out;
1038 unsigned int px;
1039 bool set_p;
1041 bb = loop_tree_node->bb;
1042 if (bb != NULL)
1044 for (i = 0; i < ira_reg_class_cover_size; i++)
1046 curr_reg_pressure[ira_reg_class_cover[i]] = 0;
1047 high_pressure_start_point[ira_reg_class_cover[i]] = -1;
1049 curr_bb_node = loop_tree_node;
1050 reg_live_out = DF_LR_OUT (bb);
1051 sparseset_clear (objects_live);
1052 REG_SET_TO_HARD_REG_SET (hard_regs_live, reg_live_out);
1053 AND_COMPL_HARD_REG_SET (hard_regs_live, eliminable_regset);
1054 AND_COMPL_HARD_REG_SET (hard_regs_live, ira_no_alloc_regs);
1055 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1056 if (TEST_HARD_REG_BIT (hard_regs_live, i))
1058 enum reg_class cover_class, cl;
1060 cover_class = ira_class_translate[REGNO_REG_CLASS (i)];
1061 for (j = 0;
1062 (cl = ira_reg_class_super_classes[cover_class][j])
1063 != LIM_REG_CLASSES;
1064 j++)
1066 curr_reg_pressure[cl]++;
1067 if (curr_bb_node->reg_pressure[cl] < curr_reg_pressure[cl])
1068 curr_bb_node->reg_pressure[cl] = curr_reg_pressure[cl];
1069 ira_assert (curr_reg_pressure[cl]
1070 <= ira_available_class_regs[cl]);
1073 EXECUTE_IF_SET_IN_BITMAP (reg_live_out, FIRST_PSEUDO_REGISTER, j, bi)
1074 mark_pseudo_regno_live (j);
1076 freq = REG_FREQ_FROM_BB (bb);
1077 if (freq == 0)
1078 freq = 1;
1080 /* Invalidate all allocno_saved_at_call entries. */
1081 last_call_num++;
1083 /* Scan the code of this basic block, noting which allocnos and
1084 hard regs are born or die.
1086 Note that this loop treats uninitialized values as live until
1087 the beginning of the block. For example, if an instruction
1088 uses (reg:DI foo), and only (subreg:SI (reg:DI foo) 0) is ever
1089 set, FOO will remain live until the beginning of the block.
1090 Likewise if FOO is not set at all. This is unnecessarily
1091 pessimistic, but it probably doesn't matter much in practice. */
1092 FOR_BB_INSNS_REVERSE (bb, insn)
1094 df_ref *def_rec, *use_rec;
1095 bool call_p;
1097 if (!NONDEBUG_INSN_P (insn))
1098 continue;
1100 if (internal_flag_ira_verbose > 2 && ira_dump_file != NULL)
1101 fprintf (ira_dump_file, " Insn %u(l%d): point = %d\n",
1102 INSN_UID (insn), loop_tree_node->parent->loop->num,
1103 curr_point);
1105 /* Mark each defined value as live. We need to do this for
1106 unused values because they still conflict with quantities
1107 that are live at the time of the definition.
1109 Ignore DF_REF_MAY_CLOBBERs on a call instruction. Such
1110 references represent the effect of the called function
1111 on a call-clobbered register. Marking the register as
1112 live would stop us from allocating it to a call-crossing
1113 allocno. */
1114 call_p = CALL_P (insn);
1115 for (def_rec = DF_INSN_DEFS (insn); *def_rec; def_rec++)
1116 if (!call_p || !DF_REF_FLAGS_IS_SET (*def_rec, DF_REF_MAY_CLOBBER))
1117 mark_ref_live (*def_rec);
1119 /* If INSN has multiple outputs, then any value used in one
1120 of the outputs conflicts with the other outputs. Model this
1121 by making the used value live during the output phase.
1123 It is unsafe to use !single_set here since it will ignore
1124 an unused output. Just because an output is unused does
1125 not mean the compiler can assume the side effect will not
1126 occur. Consider if ALLOCNO appears in the address of an
1127 output and we reload the output. If we allocate ALLOCNO
1128 to the same hard register as an unused output we could
1129 set the hard register before the output reload insn. */
1130 if (GET_CODE (PATTERN (insn)) == PARALLEL && multiple_sets (insn))
1131 for (use_rec = DF_INSN_USES (insn); *use_rec; use_rec++)
1133 int i;
1134 rtx reg;
1136 reg = DF_REF_REG (*use_rec);
1137 for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1139 rtx set;
1141 set = XVECEXP (PATTERN (insn), 0, i);
1142 if (GET_CODE (set) == SET
1143 && reg_overlap_mentioned_p (reg, SET_DEST (set)))
1145 /* After the previous loop, this is a no-op if
1146 REG is contained within SET_DEST (SET). */
1147 mark_ref_live (*use_rec);
1148 break;
1153 extract_insn (insn);
1154 preprocess_constraints ();
1155 process_single_reg_class_operands (false, freq);
1157 /* See which defined values die here. */
1158 for (def_rec = DF_INSN_DEFS (insn); *def_rec; def_rec++)
1159 if (!call_p || !DF_REF_FLAGS_IS_SET (*def_rec, DF_REF_MAY_CLOBBER))
1160 mark_ref_dead (*def_rec);
1162 if (call_p)
1164 last_call_num++;
1165 sparseset_clear (allocnos_processed);
1166 /* The current set of live allocnos are live across the call. */
1167 EXECUTE_IF_SET_IN_SPARSESET (objects_live, i)
1169 ira_object_t obj = ira_object_id_map[i];
1170 ira_allocno_t a = OBJECT_ALLOCNO (obj);
1171 int num = ALLOCNO_NUM (a);
1173 /* Don't allocate allocnos that cross setjmps or any
1174 call, if this function receives a nonlocal
1175 goto. */
1176 if (cfun->has_nonlocal_label
1177 || find_reg_note (insn, REG_SETJMP,
1178 NULL_RTX) != NULL_RTX)
1180 SET_HARD_REG_SET (OBJECT_CONFLICT_HARD_REGS (obj));
1181 SET_HARD_REG_SET (OBJECT_TOTAL_CONFLICT_HARD_REGS (obj));
1183 if (can_throw_internal (insn))
1185 IOR_HARD_REG_SET (OBJECT_CONFLICT_HARD_REGS (obj),
1186 call_used_reg_set);
1187 IOR_HARD_REG_SET (OBJECT_TOTAL_CONFLICT_HARD_REGS (obj),
1188 call_used_reg_set);
1191 if (sparseset_bit_p (allocnos_processed, num))
1192 continue;
1193 sparseset_set_bit (allocnos_processed, num);
1195 if (allocno_saved_at_call[num] != last_call_num)
1196 /* Here we are mimicking caller-save.c behaviour
1197 which does not save hard register at a call if
1198 it was saved on previous call in the same basic
1199 block and the hard register was not mentioned
1200 between the two calls. */
1201 ALLOCNO_CALL_FREQ (a) += freq;
1202 /* Mark it as saved at the next call. */
1203 allocno_saved_at_call[num] = last_call_num + 1;
1204 ALLOCNO_CALLS_CROSSED_NUM (a)++;
1208 make_early_clobber_and_input_conflicts ();
1210 curr_point++;
1212 /* Mark each used value as live. */
1213 for (use_rec = DF_INSN_USES (insn); *use_rec; use_rec++)
1214 mark_ref_live (*use_rec);
1216 process_single_reg_class_operands (true, freq);
1218 set_p = mark_hard_reg_early_clobbers (insn, true);
1220 if (set_p)
1222 mark_hard_reg_early_clobbers (insn, false);
1224 /* Mark each hard reg as live again. For example, a
1225 hard register can be in clobber and in an insn
1226 input. */
1227 for (use_rec = DF_INSN_USES (insn); *use_rec; use_rec++)
1229 rtx ureg = DF_REF_REG (*use_rec);
1231 if (GET_CODE (ureg) == SUBREG)
1232 ureg = SUBREG_REG (ureg);
1233 if (! REG_P (ureg) || REGNO (ureg) >= FIRST_PSEUDO_REGISTER)
1234 continue;
1236 mark_ref_live (*use_rec);
1240 curr_point++;
1243 #ifdef EH_RETURN_DATA_REGNO
1244 if (bb_has_eh_pred (bb))
1245 for (j = 0; ; ++j)
1247 unsigned int regno = EH_RETURN_DATA_REGNO (j);
1248 if (regno == INVALID_REGNUM)
1249 break;
1250 make_hard_regno_born (regno);
1252 #endif
1254 /* Allocnos can't go in stack regs at the start of a basic block
1255 that is reached by an abnormal edge. Likewise for call
1256 clobbered regs, because caller-save, fixup_abnormal_edges and
1257 possibly the table driven EH machinery are not quite ready to
1258 handle such allocnos live across such edges. */
1259 if (bb_has_abnormal_pred (bb))
1261 #ifdef STACK_REGS
1262 EXECUTE_IF_SET_IN_SPARSESET (objects_live, px)
1264 ira_allocno_t a = OBJECT_ALLOCNO (ira_object_id_map[px]);
1265 ALLOCNO_NO_STACK_REG_P (a) = true;
1266 ALLOCNO_TOTAL_NO_STACK_REG_P (a) = true;
1268 for (px = FIRST_STACK_REG; px <= LAST_STACK_REG; px++)
1269 make_hard_regno_born (px);
1270 #endif
1271 /* No need to record conflicts for call clobbered regs if we
1272 have nonlocal labels around, as we don't ever try to
1273 allocate such regs in this case. */
1274 if (!cfun->has_nonlocal_label && bb_has_abnormal_call_pred (bb))
1275 for (px = 0; px < FIRST_PSEUDO_REGISTER; px++)
1276 if (call_used_regs[px])
1277 make_hard_regno_born (px);
1280 EXECUTE_IF_SET_IN_SPARSESET (objects_live, i)
1281 make_object_dead (ira_object_id_map[i]);
1283 curr_point++;
1286 /* Propagate register pressure to upper loop tree nodes: */
1287 if (loop_tree_node != ira_loop_tree_root)
1288 for (i = 0; i < ira_reg_class_cover_size; i++)
1290 enum reg_class cover_class;
1292 cover_class = ira_reg_class_cover[i];
1293 if (loop_tree_node->reg_pressure[cover_class]
1294 > loop_tree_node->parent->reg_pressure[cover_class])
1295 loop_tree_node->parent->reg_pressure[cover_class]
1296 = loop_tree_node->reg_pressure[cover_class];
1300 /* Create and set up IRA_START_POINT_RANGES and
1301 IRA_FINISH_POINT_RANGES. */
1302 static void
1303 create_start_finish_chains (void)
1305 ira_object_t obj;
1306 ira_object_iterator oi;
1307 live_range_t r;
1309 ira_start_point_ranges
1310 = (live_range_t *) ira_allocate (ira_max_point * sizeof (live_range_t));
1311 memset (ira_start_point_ranges, 0, ira_max_point * sizeof (live_range_t));
1312 ira_finish_point_ranges
1313 = (live_range_t *) ira_allocate (ira_max_point * sizeof (live_range_t));
1314 memset (ira_finish_point_ranges, 0, ira_max_point * sizeof (live_range_t));
1315 FOR_EACH_OBJECT (obj, oi)
1316 for (r = OBJECT_LIVE_RANGES (obj); r != NULL; r = r->next)
1318 r->start_next = ira_start_point_ranges[r->start];
1319 ira_start_point_ranges[r->start] = r;
1320 r->finish_next = ira_finish_point_ranges[r->finish];
1321 ira_finish_point_ranges[r->finish] = r;
1325 /* Rebuild IRA_START_POINT_RANGES and IRA_FINISH_POINT_RANGES after
1326 new live ranges and program points were added as a result if new
1327 insn generation. */
1328 void
1329 ira_rebuild_start_finish_chains (void)
1331 ira_free (ira_finish_point_ranges);
1332 ira_free (ira_start_point_ranges);
1333 create_start_finish_chains ();
1336 /* Compress allocno live ranges by removing program points where
1337 nothing happens. */
1338 static void
1339 remove_some_program_points_and_update_live_ranges (void)
1341 unsigned i;
1342 int n;
1343 int *map;
1344 ira_object_t obj;
1345 ira_object_iterator oi;
1346 live_range_t r;
1347 sbitmap born_or_dead, born, dead;
1348 sbitmap_iterator sbi;
1349 bool born_p, dead_p, prev_born_p, prev_dead_p;
1351 born = sbitmap_alloc (ira_max_point);
1352 dead = sbitmap_alloc (ira_max_point);
1353 sbitmap_zero (born);
1354 sbitmap_zero (dead);
1355 FOR_EACH_OBJECT (obj, oi)
1356 for (r = OBJECT_LIVE_RANGES (obj); r != NULL; r = r->next)
1358 ira_assert (r->start <= r->finish);
1359 SET_BIT (born, r->start);
1360 SET_BIT (dead, r->finish);
1363 born_or_dead = sbitmap_alloc (ira_max_point);
1364 sbitmap_a_or_b (born_or_dead, born, dead);
1365 map = (int *) ira_allocate (sizeof (int) * ira_max_point);
1366 n = -1;
1367 prev_born_p = prev_dead_p = false;
1368 EXECUTE_IF_SET_IN_SBITMAP (born_or_dead, 0, i, sbi)
1370 born_p = TEST_BIT (born, i);
1371 dead_p = TEST_BIT (dead, i);
1372 if ((prev_born_p && ! prev_dead_p && born_p && ! dead_p)
1373 || (prev_dead_p && ! prev_born_p && dead_p && ! born_p))
1374 map[i] = n;
1375 else
1376 map[i] = ++n;
1377 prev_born_p = born_p;
1378 prev_dead_p = dead_p;
1380 sbitmap_free (born_or_dead);
1381 sbitmap_free (born);
1382 sbitmap_free (dead);
1383 n++;
1384 if (internal_flag_ira_verbose > 1 && ira_dump_file != NULL)
1385 fprintf (ira_dump_file, "Compressing live ranges: from %d to %d - %d%%\n",
1386 ira_max_point, n, 100 * n / ira_max_point);
1387 ira_max_point = n;
1389 FOR_EACH_OBJECT (obj, oi)
1390 for (r = OBJECT_LIVE_RANGES (obj); r != NULL; r = r->next)
1392 r->start = map[r->start];
1393 r->finish = map[r->finish];
1396 ira_free (map);
1399 /* Print live ranges R to file F. */
1400 void
1401 ira_print_live_range_list (FILE *f, live_range_t r)
1403 for (; r != NULL; r = r->next)
1404 fprintf (f, " [%d..%d]", r->start, r->finish);
1405 fprintf (f, "\n");
1408 /* Print live ranges R to stderr. */
1409 void
1410 ira_debug_live_range_list (live_range_t r)
1412 ira_print_live_range_list (stderr, r);
1415 /* Print live ranges of object OBJ to file F. */
1416 static void
1417 print_object_live_ranges (FILE *f, ira_object_t obj)
1419 ira_print_live_range_list (f, OBJECT_LIVE_RANGES (obj));
1422 /* Print live ranges of allocno A to file F. */
1423 static void
1424 print_allocno_live_ranges (FILE *f, ira_allocno_t a)
1426 int n = ALLOCNO_NUM_OBJECTS (a);
1427 int i;
1428 for (i = 0; i < n; i++)
1430 fprintf (f, " a%d(r%d", ALLOCNO_NUM (a), ALLOCNO_REGNO (a));
1431 if (n > 1)
1432 fprintf (f, " [%d]", i);
1433 fprintf (f, "):");
1434 print_object_live_ranges (f, ALLOCNO_OBJECT (a, i));
1438 /* Print live ranges of allocno A to stderr. */
1439 void
1440 ira_debug_allocno_live_ranges (ira_allocno_t a)
1442 print_allocno_live_ranges (stderr, a);
1445 /* Print live ranges of all allocnos to file F. */
1446 static void
1447 print_live_ranges (FILE *f)
1449 ira_allocno_t a;
1450 ira_allocno_iterator ai;
1452 FOR_EACH_ALLOCNO (a, ai)
1453 print_allocno_live_ranges (f, a);
1456 /* Print live ranges of all allocnos to stderr. */
1457 void
1458 ira_debug_live_ranges (void)
1460 print_live_ranges (stderr);
1463 /* The main entry function creates live ranges, set up
1464 CONFLICT_HARD_REGS and TOTAL_CONFLICT_HARD_REGS for objects, and
1465 calculate register pressure info. */
1466 void
1467 ira_create_allocno_live_ranges (void)
1469 objects_live = sparseset_alloc (ira_objects_num);
1470 allocnos_processed = sparseset_alloc (ira_allocnos_num);
1471 curr_point = 0;
1472 last_call_num = 0;
1473 allocno_saved_at_call
1474 = (int *) ira_allocate (ira_allocnos_num * sizeof (int));
1475 memset (allocno_saved_at_call, 0, ira_allocnos_num * sizeof (int));
1476 ira_traverse_loop_tree (true, ira_loop_tree_root, NULL,
1477 process_bb_node_lives);
1478 ira_max_point = curr_point;
1479 create_start_finish_chains ();
1480 if (internal_flag_ira_verbose > 2 && ira_dump_file != NULL)
1481 print_live_ranges (ira_dump_file);
1482 /* Clean up. */
1483 ira_free (allocno_saved_at_call);
1484 sparseset_free (objects_live);
1485 sparseset_free (allocnos_processed);
1488 /* Compress allocno live ranges. */
1489 void
1490 ira_compress_allocno_live_ranges (void)
1492 remove_some_program_points_and_update_live_ranges ();
1493 ira_rebuild_start_finish_chains ();
1494 if (internal_flag_ira_verbose > 2 && ira_dump_file != NULL)
1496 fprintf (ira_dump_file, "Ranges after the compression:\n");
1497 print_live_ranges (ira_dump_file);
1501 /* Free arrays IRA_START_POINT_RANGES and IRA_FINISH_POINT_RANGES. */
1502 void
1503 ira_finish_allocno_live_ranges (void)
1505 ira_free (ira_finish_point_ranges);
1506 ira_free (ira_start_point_ranges);