1 /* IRA processing allocno lives to build allocno live ranges.
2 Copyright (C) 2006, 2007, 2008
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
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
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/>. */
24 #include "coretypes.h"
31 #include "hard-reg-set.h"
32 #include "basic-block.h"
33 #include "insn-config.h"
38 #include "sparseset.h"
41 /* The code in this file is similar to one in global but the code
42 works on the allocno basis and creates live ranges instead of
43 pseudo-register conflicts. */
45 static void make_regno_born (int);
46 static void update_allocno_pressure_excess_length (allocno_t
);
47 static void make_regno_dead (int);
48 static void make_regno_born_and_dead (int);
49 static void set_allocno_live (allocno_t
);
50 static void clear_allocno_live (allocno_t
);
51 static void mark_reg_store (rtx
, const_rtx
, void *);
52 static void mark_reg_clobber (rtx
, const_rtx
, void *);
53 static void mark_reg_conflicts (rtx
);
54 static void mark_reg_death (rtx
);
55 static enum reg_class
single_reg_class (const char *, rtx op
, rtx
);
56 static enum reg_class
single_reg_operand_class (int);
57 static void process_single_reg_class_operands (int, int);
58 static void process_bb_node_lives (loop_tree_node_t
);
59 static void create_start_finish_chains (void);
60 static void print_allocno_live_ranges (FILE *, allocno_t
);
61 static void print_live_ranges (FILE *);
62 static void propagate_new_allocno_info (allocno_t
);
63 static void propagate_new_info (void);
65 /* Program points are enumerated by number from range 0..MAX_POINT-1.
66 There are approximately tow times more program points than insns.
67 One program points correspond points between subsequent insns and
68 other ones correspond to points after usage of input operands but
69 before setting the output operands in insns. */
72 /* Arrays of size MAX_POINT mapping a program point to the allocno
73 live ranges with given start/finish point. */
74 allocno_live_range_t
*start_point_ranges
, *finish_point_ranges
;
76 /* Number of the current program point. */
77 static int curr_point
;
79 /* Point where register pressure excess started or -1 if there is no
80 register pressure excess. Excess pressure for a register class at
81 some point means that there are more allocnos of given register
82 class living at the point than number of hard-registers of the
83 class available for the allocation. It is defined only for cover
85 static int high_pressure_start_point
[N_REG_CLASSES
];
87 /* Allocnos live at current point in the scan. */
88 static sparseset allocnos_live
;
90 /* Set of hard regs (except eliminable ones) currently live. */
91 static HARD_REG_SET hard_regs_live
;
93 /* The loop tree node corresponding to the current basic block. */
94 static loop_tree_node_t curr_bb_node
;
96 /* The function processing birth of register REGNO. It updates living
97 hard regs and conflict hard regs for living allocnos or starts a
98 new live range for the allocno corresponding to REGNO if it is
101 make_regno_born (int regno
)
105 allocno_live_range_t p
;
107 if (regno
< FIRST_PSEUDO_REGISTER
)
109 SET_HARD_REG_BIT (hard_regs_live
, regno
);
110 EXECUTE_IF_SET_IN_SPARSESET (allocnos_live
, i
)
112 SET_HARD_REG_BIT (ALLOCNO_CONFLICT_HARD_REGS (allocnos
[i
]), regno
);
113 SET_HARD_REG_BIT (ALLOCNO_TOTAL_CONFLICT_HARD_REGS (allocnos
[i
]),
118 a
= ira_curr_regno_allocno_map
[regno
];
121 if ((p
= ALLOCNO_LIVE_RANGES (a
)) == NULL
122 || (p
->finish
!= curr_point
&& p
->finish
+ 1 != curr_point
))
123 ALLOCNO_LIVE_RANGES (a
)
124 = create_allocno_live_range (a
, curr_point
, -1, ALLOCNO_LIVE_RANGES (a
));
127 /* Update ALLOCNO_EXCESS_PRESSURE_POINTS_NUM for allocno A. */
129 update_allocno_pressure_excess_length (allocno_t a
)
132 enum reg_class cover_class
;
133 allocno_live_range_t p
;
135 cover_class
= ALLOCNO_COVER_CLASS (a
);
136 if (high_pressure_start_point
[cover_class
] < 0)
138 p
= ALLOCNO_LIVE_RANGES (a
);
139 ira_assert (p
!= NULL
);
140 start
= (high_pressure_start_point
[cover_class
] > p
->start
141 ? high_pressure_start_point
[cover_class
] : p
->start
);
142 ALLOCNO_EXCESS_PRESSURE_POINTS_NUM (a
) += curr_point
- start
+ 1;
145 /* The function processing death of register REGNO. It updates live
146 hard regs or finish the current live range for the allocno
147 corresponding to REGNO. */
149 make_regno_dead (int regno
)
152 allocno_live_range_t p
;
154 if (regno
< FIRST_PSEUDO_REGISTER
)
156 CLEAR_HARD_REG_BIT (hard_regs_live
, regno
);
159 a
= ira_curr_regno_allocno_map
[regno
];
162 p
= ALLOCNO_LIVE_RANGES (a
);
163 ira_assert (p
!= NULL
);
164 p
->finish
= curr_point
;
165 update_allocno_pressure_excess_length (a
);
168 /* The function processing birth and, right after then, death of
171 make_regno_born_and_dead (int regno
)
173 make_regno_born (regno
);
174 make_regno_dead (regno
);
177 /* The current register pressures for each cover class for the current
179 static int curr_reg_pressure
[N_REG_CLASSES
];
181 /* The function marks allocno A as currently living and updates
182 current register pressure, maximal register pressure for the
183 current BB, start point of the register pressure excess, and
184 conflicting hard registers of A. */
186 set_allocno_live (allocno_t a
)
189 enum reg_class cover_class
;
191 if (sparseset_bit_p (allocnos_live
, ALLOCNO_NUM (a
)))
193 sparseset_set_bit (allocnos_live
, ALLOCNO_NUM (a
));
194 IOR_HARD_REG_SET (ALLOCNO_CONFLICT_HARD_REGS (a
), hard_regs_live
);
195 IOR_HARD_REG_SET (ALLOCNO_TOTAL_CONFLICT_HARD_REGS (a
), hard_regs_live
);
196 cover_class
= ALLOCNO_COVER_CLASS (a
);
197 nregs
= reg_class_nregs
[cover_class
][ALLOCNO_MODE (a
)];
198 curr_reg_pressure
[cover_class
] += nregs
;
199 if (high_pressure_start_point
[cover_class
] < 0
200 && curr_reg_pressure
[cover_class
] > available_class_regs
[cover_class
])
201 high_pressure_start_point
[cover_class
] = curr_point
;
202 if (curr_bb_node
->reg_pressure
[cover_class
]
203 < curr_reg_pressure
[cover_class
])
204 curr_bb_node
->reg_pressure
[cover_class
] = curr_reg_pressure
[cover_class
];
207 /* The function marks allocno A as currently not living and updates
208 current register pressure, start point of the register pressure
209 excess, and register pressure excess length for living
212 clear_allocno_live (allocno_t a
)
215 enum reg_class cover_class
;
217 if (sparseset_bit_p (allocnos_live
, ALLOCNO_NUM (a
)))
219 cover_class
= ALLOCNO_COVER_CLASS (a
);
220 curr_reg_pressure
[cover_class
]
221 -= reg_class_nregs
[cover_class
][ALLOCNO_MODE (a
)];
222 ira_assert (curr_reg_pressure
[cover_class
] >= 0);
223 if (high_pressure_start_point
[cover_class
] >= 0
224 && (curr_reg_pressure
[cover_class
]
225 <= available_class_regs
[cover_class
]))
227 EXECUTE_IF_SET_IN_SPARSESET (allocnos_live
, i
)
229 update_allocno_pressure_excess_length (allocnos
[i
]);
231 high_pressure_start_point
[cover_class
] = -1;
234 sparseset_clear_bit (allocnos_live
, ALLOCNO_NUM (a
));
237 /* Record all regs that are set in any one insn. Communication from
238 mark_reg_{store,clobber}. */
239 static VEC(rtx
, heap
) *regs_set
;
241 /* Handle the case where REG is set by the insn being scanned, during
242 the scan to build live ranges and calculate reg pressure info.
243 Store a 1 in hard_regs_live or allocnos_live for this register or
244 the corresponding allocno, record how many consecutive hardware
245 registers it actually needs.
247 Note that even if REG does not remain alive after this insn, we
248 must mark it here as live, to ensure a conflict between REG and any
249 other reg allocnos set in this insn that really do live. This is
250 because those other allocnos could be considered after this.
252 REG might actually be something other than a register; if so, we do
255 SETTER is 0 if this register was modified by an auto-increment
256 (i.e., a REG_INC note was found for it). */
258 mark_reg_store (rtx reg
, const_rtx setter ATTRIBUTE_UNUSED
,
259 void *data ATTRIBUTE_UNUSED
)
263 if (GET_CODE (reg
) == SUBREG
)
264 reg
= SUBREG_REG (reg
);
269 VEC_safe_push (rtx
, heap
, regs_set
, reg
);
273 if (regno
>= FIRST_PSEUDO_REGISTER
)
275 allocno_t a
= ira_curr_regno_allocno_map
[regno
];
279 if (sparseset_bit_p (allocnos_live
, ALLOCNO_NUM (a
)))
281 set_allocno_live (a
);
283 make_regno_born (regno
);
285 else if (! TEST_HARD_REG_BIT (no_alloc_regs
, regno
))
287 int last
= regno
+ hard_regno_nregs
[regno
][GET_MODE (reg
)];
288 enum reg_class cover_class
;
292 if (! TEST_HARD_REG_BIT (hard_regs_live
, regno
)
293 && ! TEST_HARD_REG_BIT (eliminable_regset
, regno
))
295 cover_class
= class_translate
[REGNO_REG_CLASS (regno
)];
296 if (cover_class
!= NO_REGS
)
298 curr_reg_pressure
[cover_class
]++;
299 if (high_pressure_start_point
[cover_class
] < 0
300 && (curr_reg_pressure
[cover_class
]
301 > available_class_regs
[cover_class
]))
302 high_pressure_start_point
[cover_class
] = curr_point
;
304 make_regno_born (regno
);
305 if (cover_class
!= NO_REGS
306 && (curr_bb_node
->reg_pressure
[cover_class
]
307 < curr_reg_pressure
[cover_class
]))
308 curr_bb_node
->reg_pressure
[cover_class
]
309 = curr_reg_pressure
[cover_class
];
316 /* Like mark_reg_store except notice just CLOBBERs; ignore SETs. */
318 mark_reg_clobber (rtx reg
, const_rtx setter
, void *data
)
320 if (GET_CODE (setter
) == CLOBBER
)
321 mark_reg_store (reg
, setter
, data
);
324 /* Record that hard register REG (if it is a hard register) has
325 conflicts with all the allocno currently live or the corresponding
326 allocno lives at just the current program point. Do not mark REG
327 (or the allocno) itself as live. */
329 mark_reg_conflicts (rtx reg
)
333 if (GET_CODE (reg
) == SUBREG
)
334 reg
= SUBREG_REG (reg
);
341 if (regno
>= FIRST_PSEUDO_REGISTER
)
342 make_regno_born_and_dead (regno
);
343 else if (! TEST_HARD_REG_BIT (no_alloc_regs
, regno
))
345 int last
= regno
+ hard_regno_nregs
[regno
][GET_MODE (reg
)];
349 make_regno_born_and_dead (regno
);
355 /* Mark REG (or the corresponding allocno) as being dead (following
356 the insn being scanned now). Store a 0 in hard_regs_live or
357 allocnos_live for the register. */
359 mark_reg_death (rtx reg
)
362 int regno
= REGNO (reg
);
364 if (regno
>= FIRST_PSEUDO_REGISTER
)
366 allocno_t a
= ira_curr_regno_allocno_map
[regno
];
370 if (! sparseset_bit_p (allocnos_live
, ALLOCNO_NUM (a
)))
372 clear_allocno_live (a
);
374 make_regno_dead (regno
);
376 else if (! TEST_HARD_REG_BIT (no_alloc_regs
, regno
))
378 int last
= regno
+ hard_regno_nregs
[regno
][GET_MODE (reg
)];
379 enum reg_class cover_class
;
383 if (TEST_HARD_REG_BIT (hard_regs_live
, regno
))
385 cover_class
= class_translate
[REGNO_REG_CLASS (regno
)];
386 if (cover_class
!= NO_REGS
)
388 curr_reg_pressure
[cover_class
]--;
389 if (high_pressure_start_point
[cover_class
] >= 0
390 && (curr_reg_pressure
[cover_class
]
391 <= available_class_regs
[cover_class
]))
393 EXECUTE_IF_SET_IN_SPARSESET (allocnos_live
, i
)
395 update_allocno_pressure_excess_length (allocnos
[i
]);
397 high_pressure_start_point
[cover_class
] = -1;
399 ira_assert (curr_reg_pressure
[cover_class
] >= 0);
401 make_regno_dead (regno
);
408 /* The function checks that CONSTRAINTS permits to use only one hard
409 register. If it is so, the function returns the class of the hard
410 register. Otherwise it returns NO_REGS. */
411 static enum reg_class
412 single_reg_class (const char *constraints
, rtx op
, rtx equiv_const
)
415 enum reg_class cl
, next_cl
;
419 for (ignore_p
= FALSE
;
421 constraints
+= CONSTRAINT_LEN (c
, constraints
))
441 || (equiv_const
!= NULL_RTX
&& CONSTANT_P (equiv_const
)))
446 if (GET_CODE (op
) == CONST_INT
447 || (GET_CODE (op
) == CONST_DOUBLE
&& GET_MODE (op
) == VOIDmode
)
448 || (equiv_const
!= NULL_RTX
449 && (GET_CODE (equiv_const
) == CONST_INT
450 || (GET_CODE (equiv_const
) == CONST_DOUBLE
451 && GET_MODE (equiv_const
) == VOIDmode
))))
456 if ((CONSTANT_P (op
) && GET_CODE (op
) != CONST_INT
457 && (GET_CODE (op
) != CONST_DOUBLE
|| GET_MODE (op
) != VOIDmode
))
458 || (equiv_const
!= NULL_RTX
459 && CONSTANT_P (equiv_const
)
460 && GET_CODE (equiv_const
) != CONST_INT
461 && (GET_CODE (equiv_const
) != CONST_DOUBLE
462 || GET_MODE (equiv_const
) != VOIDmode
)))
474 if ((GET_CODE (op
) == CONST_INT
475 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op
), c
, constraints
))
476 || (equiv_const
!= NULL_RTX
477 && GET_CODE (equiv_const
) == CONST_INT
478 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (equiv_const
),
485 if (GET_CODE (op
) == CONST_DOUBLE
486 || (GET_CODE (op
) == CONST_VECTOR
487 && GET_MODE_CLASS (GET_MODE (op
)) == MODE_VECTOR_FLOAT
)
488 || (equiv_const
!= NULL_RTX
489 && (GET_CODE (equiv_const
) == CONST_DOUBLE
490 || (GET_CODE (equiv_const
) == CONST_VECTOR
491 && (GET_MODE_CLASS (GET_MODE (equiv_const
))
492 == MODE_VECTOR_FLOAT
)))))
498 if ((GET_CODE (op
) == CONST_DOUBLE
499 && CONST_DOUBLE_OK_FOR_CONSTRAINT_P (op
, c
, constraints
))
500 || (equiv_const
!= NULL_RTX
501 && GET_CODE (equiv_const
) == CONST_DOUBLE
502 && CONST_DOUBLE_OK_FOR_CONSTRAINT_P (equiv_const
,
505 /* ??? what about memory */
507 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
508 case 'h': case 'j': case 'k': case 'l':
509 case 'q': case 't': case 'u':
510 case 'v': case 'w': case 'x': case 'y': case 'z':
511 case 'A': case 'B': case 'C': case 'D':
512 case 'Q': case 'R': case 'S': case 'T': case 'U':
513 case 'W': case 'Y': case 'Z':
516 : REG_CLASS_FROM_CONSTRAINT (c
, constraints
));
517 if ((cl
!= NO_REGS
&& next_cl
!= cl
)
518 || available_class_regs
[next_cl
] > 1)
523 case '0': case '1': case '2': case '3': case '4':
524 case '5': case '6': case '7': case '8': case '9':
526 = single_reg_class (recog_data
.constraints
[c
- '0'],
527 recog_data
.operand
[c
- '0'], NULL_RTX
);
528 if ((cl
!= NO_REGS
&& next_cl
!= cl
) || next_cl
== NO_REGS
529 || available_class_regs
[next_cl
] > 1)
540 /* The function checks that operand OP_NUM of the current insn can use
541 only one hard register. If it is so, the function returns the
542 class of the hard register. Otherwise it returns NO_REGS. */
543 static enum reg_class
544 single_reg_operand_class (int op_num
)
546 if (op_num
< 0 || recog_data
.n_alternatives
== 0)
548 return single_reg_class (recog_data
.constraints
[op_num
],
549 recog_data
.operand
[op_num
], NULL_RTX
);
552 /* The function processes input operands, if IN_P, or output operands
553 otherwise of the current insn with FREQ to find allocno which can
554 use only one hard register and makes other currently living
555 allocnos conflicting with the hard register. */
557 process_single_reg_class_operands (int in_p
, int freq
)
561 enum reg_class cl
, cover_class
;
563 allocno_t operand_a
, a
;
565 for (i
= 0; i
< recog_data
.n_operands
; i
++)
567 operand
= recog_data
.operand
[i
];
568 if (in_p
&& recog_data
.operand_type
[i
] != OP_IN
569 && recog_data
.operand_type
[i
] != OP_INOUT
)
571 if (! in_p
&& recog_data
.operand_type
[i
] != OP_OUT
572 && recog_data
.operand_type
[i
] != OP_INOUT
)
574 cl
= single_reg_operand_class (i
);
580 if (GET_CODE (operand
) == SUBREG
)
581 operand
= SUBREG_REG (operand
);
584 && (regno
= REGNO (operand
)) >= FIRST_PSEUDO_REGISTER
)
586 enum machine_mode mode
;
587 enum reg_class cover_class
;
589 operand_a
= ira_curr_regno_allocno_map
[regno
];
590 mode
= ALLOCNO_MODE (operand_a
);
591 cover_class
= ALLOCNO_COVER_CLASS (operand_a
);
592 if (class_subset_p
[cl
][cover_class
]
593 && class_hard_regs_num
[cl
] != 0
594 && class_hard_reg_index
[cover_class
][class_hard_regs
[cl
][0]] >= 0
595 && reg_class_size
[cl
] <= (unsigned) CLASS_MAX_NREGS (cl
, mode
))
599 ? register_move_cost
[mode
][cover_class
][cl
]
600 : register_move_cost
[mode
][cl
][cover_class
]);
601 allocate_and_set_costs
602 (&ALLOCNO_CONFLICT_HARD_REG_COSTS (operand_a
), cover_class
, 0);
603 ALLOCNO_CONFLICT_HARD_REG_COSTS (operand_a
)
604 [class_hard_reg_index
[cover_class
][class_hard_regs
[cl
][0]]]
609 EXECUTE_IF_SET_IN_SPARSESET (allocnos_live
, px
)
612 cover_class
= ALLOCNO_COVER_CLASS (a
);
615 /* We could increase costs of A instead of making it
616 conflicting with the hard register. But it works worse
617 because it will be spilled in reload in anyway. */
618 IOR_HARD_REG_SET (ALLOCNO_CONFLICT_HARD_REGS (a
),
619 reg_class_contents
[cl
]);
620 IOR_HARD_REG_SET (ALLOCNO_TOTAL_CONFLICT_HARD_REGS (a
),
621 reg_class_contents
[cl
]);
627 /* The function processes insns of the basic block given by its
628 LOOP_TREE_NODE to update allocno live ranges, allocno hard register
629 conflicts, intersected calls, and register pressure info for
630 allocnos for the basic block for and regions containing the basic
633 process_bb_node_lives (loop_tree_node_t loop_tree_node
)
645 bb
= loop_tree_node
->bb
;
648 for (i
= 0; i
< reg_class_cover_size
; i
++)
650 curr_reg_pressure
[reg_class_cover
[i
]] = 0;
651 high_pressure_start_point
[reg_class_cover
[i
]] = -1;
653 curr_bb_node
= loop_tree_node
;
654 reg_live_in
= DF_LR_IN (bb
);
655 sparseset_clear (allocnos_live
);
656 REG_SET_TO_HARD_REG_SET (hard_regs_live
, reg_live_in
);
657 AND_COMPL_HARD_REG_SET (hard_regs_live
, eliminable_regset
);
658 AND_COMPL_HARD_REG_SET (hard_regs_live
, no_alloc_regs
);
659 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
660 if (TEST_HARD_REG_BIT (hard_regs_live
, i
))
662 enum reg_class cover_class
;
664 cover_class
= REGNO_REG_CLASS (i
);
665 if (cover_class
== NO_REGS
)
667 cover_class
= class_translate
[cover_class
];
668 curr_reg_pressure
[cover_class
]++;
669 if (curr_bb_node
->reg_pressure
[cover_class
]
670 < curr_reg_pressure
[cover_class
])
671 curr_bb_node
->reg_pressure
[cover_class
]
672 = curr_reg_pressure
[cover_class
];
673 ira_assert (curr_reg_pressure
[cover_class
]
674 <= available_class_regs
[cover_class
]);
676 EXECUTE_IF_SET_IN_BITMAP (reg_live_in
, FIRST_PSEUDO_REGISTER
, j
, bi
)
678 allocno_t a
= ira_curr_regno_allocno_map
[j
];
682 ira_assert (! sparseset_bit_p (allocnos_live
, ALLOCNO_NUM (a
)));
683 set_allocno_live (a
);
687 #ifdef EH_RETURN_DATA_REGNO
688 if (bb_has_eh_pred (bb
))
692 unsigned int regno
= EH_RETURN_DATA_REGNO (j
);
694 if (regno
== INVALID_REGNUM
)
696 make_regno_born_and_dead (regno
);
701 /* Allocnos can't go in stack regs at the start of a basic block
702 that is reached by an abnormal edge. Likewise for call
703 clobbered regs, because caller-save, fixup_abnormal_edges and
704 possibly the table driven EH machinery are not quite ready to
705 handle such allocnos live across such edges. */
706 FOR_EACH_EDGE (e
, ei
, bb
->preds
)
707 if (e
->flags
& EDGE_ABNORMAL
)
713 EXECUTE_IF_SET_IN_SPARSESET (allocnos_live
, px
)
715 ALLOCNO_NO_STACK_REG_P (allocnos
[px
]) = TRUE
;
716 ALLOCNO_TOTAL_NO_STACK_REG_P (allocnos
[px
]) = TRUE
;
718 for (px
= FIRST_STACK_REG
; px
<= LAST_STACK_REG
; px
++)
719 make_regno_born_and_dead (px
);
721 /* No need to record conflicts for call clobbered regs if we
722 have nonlocal labels around, as we don't ever try to
723 allocate such regs in this case. */
724 if (!cfun
->has_nonlocal_label
)
725 for (px
= 0; px
< FIRST_PSEUDO_REGISTER
; px
++)
726 if (call_used_regs
[px
])
727 make_regno_born_and_dead (px
);
730 /* Scan the code of this basic block, noting which allocnos and
731 hard regs are born or die. */
732 FOR_BB_INSNS (bb
, insn
)
740 freq
= REG_FREQ_FROM_BB (BLOCK_FOR_INSN (insn
));
744 if (internal_flag_ira_verbose
> 2 && ira_dump_file
!= NULL
)
745 fprintf (ira_dump_file
, " Insn %u(l%d): point = %d\n",
746 INSN_UID (insn
), loop_tree_node
->father
->loop
->num
,
749 /* Check regs_set is an empty set. */
750 gcc_assert (VEC_empty (rtx
, regs_set
));
752 /* Mark any allocnos clobbered by INSN as live, so they
753 conflict with the inputs. */
754 note_stores (PATTERN (insn
), mark_reg_clobber
, NULL
);
757 process_single_reg_class_operands (TRUE
, freq
);
759 /* Mark any allocnos dead after INSN as dead now. */
760 for (link
= REG_NOTES (insn
); link
; link
= XEXP (link
, 1))
761 if (REG_NOTE_KIND (link
) == REG_DEAD
)
762 mark_reg_death (XEXP (link
, 0));
768 HARD_REG_SET clobbered_regs
;
770 get_call_invalidated_used_regs (insn
, &clobbered_regs
, FALSE
);
771 IOR_HARD_REG_SET (crtl
->emit
.call_used_regs
, clobbered_regs
);
772 EXECUTE_IF_SET_IN_SPARSESET (allocnos_live
, i
)
774 allocno_t a
= allocnos
[i
];
776 ALLOCNO_CALL_FREQ (a
) += freq
;
777 index
= add_regno_call (ALLOCNO_REGNO (a
), insn
);
778 if (ALLOCNO_CALLS_CROSSED_START (a
) < 0)
779 ALLOCNO_CALLS_CROSSED_START (a
) = index
;
780 ALLOCNO_CALLS_CROSSED_NUM (a
)++;
781 /* Don't allocate allocnos that cross calls, if this
782 function receives a nonlocal goto. */
783 if (cfun
->has_nonlocal_label
)
785 SET_HARD_REG_SET (ALLOCNO_CONFLICT_HARD_REGS (a
));
786 SET_HARD_REG_SET (ALLOCNO_TOTAL_CONFLICT_HARD_REGS (a
));
791 /* Mark any allocnos set in INSN as live. Clobbers are
792 processed again, so they will conflict with the reg
793 allocnos that are set. */
794 note_stores (PATTERN (insn
), mark_reg_store
, NULL
);
797 for (link
= REG_NOTES (insn
); link
; link
= XEXP (link
, 1))
798 if (REG_NOTE_KIND (link
) == REG_INC
)
799 mark_reg_store (XEXP (link
, 0), NULL_RTX
, NULL
);
802 /* If INSN has multiple outputs, then any allocno that dies
803 here and is used inside of an output must conflict with
806 It is unsafe to use !single_set here since it will ignore
807 an unused output. Just because an output is unused does
808 not mean the compiler can assume the side effect will not
809 occur. Consider if ALLOCNO appears in the address of an
810 output and we reload the output. If we allocate ALLOCNO
811 to the same hard register as an unused output we could
812 set the hard register before the output reload insn. */
813 if (GET_CODE (PATTERN (insn
)) == PARALLEL
&& multiple_sets (insn
))
814 for (link
= REG_NOTES (insn
); link
; link
= XEXP (link
, 1))
815 if (REG_NOTE_KIND (link
) == REG_DEAD
)
818 int used_in_output
= 0;
819 rtx reg
= XEXP (link
, 0);
821 for (i
= XVECLEN (PATTERN (insn
), 0) - 1; i
>= 0; i
--)
823 rtx set
= XVECEXP (PATTERN (insn
), 0, i
);
825 if (GET_CODE (set
) == SET
826 && ! REG_P (SET_DEST (set
))
827 && ! rtx_equal_p (reg
, SET_DEST (set
))
828 && reg_overlap_mentioned_p (reg
, SET_DEST (set
)))
832 mark_reg_conflicts (reg
);
835 process_single_reg_class_operands (FALSE
, freq
);
837 /* Mark any allocnos set in INSN and then never used. */
838 while (! VEC_empty (rtx
, regs_set
))
840 rtx reg
= VEC_pop (rtx
, regs_set
);
841 rtx note
= find_regno_note (insn
, REG_UNUSED
, REGNO (reg
));
844 mark_reg_death (XEXP (note
, 0));
848 EXECUTE_IF_SET_IN_SPARSESET (allocnos_live
, i
)
850 make_regno_dead (ALLOCNO_REGNO (allocnos
[i
]));
856 /* Propagate register pressure to upper loop tree nodes: */
857 if (loop_tree_node
!= ira_loop_tree_root
)
858 for (i
= 0; i
< reg_class_cover_size
; i
++)
860 enum reg_class cover_class
;
862 cover_class
= reg_class_cover
[i
];
863 if (loop_tree_node
->reg_pressure
[cover_class
]
864 > loop_tree_node
->father
->reg_pressure
[cover_class
])
865 loop_tree_node
->father
->reg_pressure
[cover_class
]
866 = loop_tree_node
->reg_pressure
[cover_class
];
870 /* The function creates and sets up START_POINT_RANGES and
871 FINISH_POINT_RANGES. */
873 create_start_finish_chains (void)
877 allocno_live_range_t r
;
880 = ira_allocate (max_point
* sizeof (allocno_live_range_t
));
881 memset (start_point_ranges
, 0, max_point
* sizeof (allocno_live_range_t
));
883 = ira_allocate (max_point
* sizeof (allocno_live_range_t
));
884 memset (finish_point_ranges
, 0, max_point
* sizeof (allocno_live_range_t
));
885 FOR_EACH_ALLOCNO (a
, ai
)
887 for (r
= ALLOCNO_LIVE_RANGES (a
); r
!= NULL
; r
= r
->next
)
889 r
->start_next
= start_point_ranges
[r
->start
];
890 start_point_ranges
[r
->start
] = r
;
891 r
->finish_next
= finish_point_ranges
[r
->finish
];
892 finish_point_ranges
[r
->finish
] = r
;
897 /* The function is used to rebuild START_POINT_RANGES and
898 FINISH_POINT_RANGES after new live ranges and program points were
899 added as a result if new insn generation. */
901 rebuild_start_finish_chains (void)
903 ira_free (finish_point_ranges
);
904 ira_free (start_point_ranges
);
905 create_start_finish_chains ();
908 /* The function prints live ranges R to file F. */
910 print_live_range_list (FILE *f
, allocno_live_range_t r
)
912 for (; r
!= NULL
; r
= r
->next
)
913 fprintf (f
, " [%d..%d]", r
->start
, r
->finish
);
917 /* The function prints live ranges R to stderr. */
919 debug_live_range_list (allocno_live_range_t r
)
921 print_live_range_list (stderr
, r
);
924 /* The function prints live ranges of allocno A to file F. */
926 print_allocno_live_ranges (FILE *f
, allocno_t a
)
928 fprintf (f
, " a%d(r%d):", ALLOCNO_NUM (a
), ALLOCNO_REGNO (a
));
929 print_live_range_list (f
, ALLOCNO_LIVE_RANGES (a
));
932 /* The function prints live ranges of allocno A to stderr. */
934 debug_allocno_live_ranges (allocno_t a
)
936 print_allocno_live_ranges (stderr
, a
);
939 /* The function prints live ranges of all allocnos to file F. */
941 print_live_ranges (FILE *f
)
946 FOR_EACH_ALLOCNO (a
, ai
)
947 print_allocno_live_ranges (f
, a
);
950 /* The function prints live ranges of all allocnos to stderr. */
952 debug_live_ranges (void)
954 print_live_ranges (stderr
);
957 /* The function propagates new info about allocno A (see comments
958 about accumulated info in allocno definition) to the corresponding
959 allocno on upper loop tree level. So allocnos on upper levels
960 accumulate information about the corresponding allocnos in nested
961 regions. The new info means allocno info finally calculated in
964 propagate_new_allocno_info (allocno_t a
)
968 loop_tree_node_t father
;
970 regno
= ALLOCNO_REGNO (a
);
971 if ((father
= ALLOCNO_LOOP_TREE_NODE (a
)->father
) != NULL
972 && (father_a
= father
->regno_allocno_map
[regno
]) != NULL
)
974 ALLOCNO_CALL_FREQ (father_a
) += ALLOCNO_CALL_FREQ (a
);
976 if (ALLOCNO_TOTAL_NO_STACK_REG_P (a
))
977 ALLOCNO_TOTAL_NO_STACK_REG_P (father_a
) = TRUE
;
979 IOR_HARD_REG_SET (ALLOCNO_TOTAL_CONFLICT_HARD_REGS (father_a
),
980 ALLOCNO_TOTAL_CONFLICT_HARD_REGS (a
));
981 if (ALLOCNO_CALLS_CROSSED_START (father_a
) < 0
982 || (ALLOCNO_CALLS_CROSSED_START (a
) >= 0
983 && (ALLOCNO_CALLS_CROSSED_START (father_a
)
984 > ALLOCNO_CALLS_CROSSED_START (a
))))
985 ALLOCNO_CALLS_CROSSED_START (father_a
)
986 = ALLOCNO_CALLS_CROSSED_START (a
);
987 ALLOCNO_CALLS_CROSSED_NUM (father_a
) += ALLOCNO_CALLS_CROSSED_NUM (a
);
988 ALLOCNO_EXCESS_PRESSURE_POINTS_NUM (father_a
)
989 += ALLOCNO_EXCESS_PRESSURE_POINTS_NUM (a
);
993 /* The function propagates new info about allocnos to the
994 corresponding allocnos on upper loop tree level. */
996 propagate_new_info (void)
1001 for (i
= max_reg_num () - 1; i
>= FIRST_PSEUDO_REGISTER
; i
--)
1002 for (a
= regno_allocno_map
[i
];
1004 a
= ALLOCNO_NEXT_REGNO_ALLOCNO (a
))
1005 propagate_new_allocno_info (a
);
1008 /* The main entry function creates live ranges, set up
1009 CONFLICT_HARD_REGS and TOTAL_CONFLICT_HARD_REGS for allocnos, and
1010 calculate register pressure info. */
1012 create_allocno_live_ranges (void)
1014 allocnos_live
= sparseset_alloc (allocnos_num
);
1015 /* Make a vector that mark_reg_{store,clobber} will store in. */
1017 regs_set
= VEC_alloc (rtx
, heap
, 10);
1019 traverse_loop_tree (TRUE
, ira_loop_tree_root
, NULL
, process_bb_node_lives
);
1020 max_point
= curr_point
;
1021 create_start_finish_chains ();
1022 if (internal_flag_ira_verbose
> 2 && ira_dump_file
!= NULL
)
1023 print_live_ranges (ira_dump_file
);
1024 propagate_new_info ();
1026 sparseset_free (allocnos_live
);
1029 /* The function frees arrays START_POINT_RANGES and
1030 FINISH_POINT_RANGES. */
1032 finish_allocno_live_ranges (void)
1034 ira_free (finish_point_ranges
);
1035 ira_free (start_point_ranges
);