Mercurial > hg > CbC > CbC_gcc
diff gcc/ira-lives.c @ 67:f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
author | nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 22 Mar 2011 17:18:12 +0900 |
parents | b7f97abdc517 |
children | 04ced10e8804 |
line wrap: on
line diff
--- a/gcc/ira-lives.c Tue May 25 18:58:51 2010 +0900 +++ b/gcc/ira-lives.c Tue Mar 22 17:18:12 2011 +0900 @@ -33,9 +33,10 @@ #include "basic-block.h" #include "insn-config.h" #include "recog.h" -#include "toplev.h" +#include "diagnostic-core.h" #include "params.h" #include "df.h" +#include "sbitmap.h" #include "sparseset.h" #include "ira-int.h" @@ -54,7 +55,7 @@ /* Arrays of size IRA_MAX_POINT mapping a program point to the allocno live ranges with given start/finish point. */ -allocno_live_range_t *ira_start_point_ranges, *ira_finish_point_ranges; +live_range_t *ira_start_point_ranges, *ira_finish_point_ranges; /* Number of the current program point. */ static int curr_point; @@ -67,8 +68,12 @@ classes. */ static int high_pressure_start_point[N_REG_CLASSES]; -/* Allocnos live at current point in the scan. */ -static sparseset allocnos_live; +/* Objects live at current point in the scan. */ +static sparseset objects_live; + +/* A temporary bitmap used in functions that wish to avoid visiting an allocno + multiple times. */ +static sparseset allocnos_processed; /* Set of hard regs (except eliminable ones) currently live. */ static HARD_REG_SET hard_regs_live; @@ -81,46 +86,56 @@ /* The number of last call at which given allocno was saved. */ static int *allocno_saved_at_call; -/* The function processing birth of register REGNO. It updates living - hard regs and conflict hard regs for living allocnos or starts a - new live range for the allocno corresponding to REGNO if it is - necessary. */ +/* Record the birth of hard register REGNO, updating hard_regs_live and + hard reg conflict information for living allocnos. */ static void -make_regno_born (int regno) +make_hard_regno_born (int regno) { unsigned int i; - ira_allocno_t a; - allocno_live_range_t p; - if (regno < FIRST_PSEUDO_REGISTER) + SET_HARD_REG_BIT (hard_regs_live, regno); + EXECUTE_IF_SET_IN_SPARSESET (objects_live, i) { - SET_HARD_REG_BIT (hard_regs_live, regno); - EXECUTE_IF_SET_IN_SPARSESET (allocnos_live, i) - { - SET_HARD_REG_BIT (ALLOCNO_CONFLICT_HARD_REGS (ira_allocnos[i]), - regno); - SET_HARD_REG_BIT (ALLOCNO_TOTAL_CONFLICT_HARD_REGS (ira_allocnos[i]), - regno); - } - return; + ira_object_t obj = ira_object_id_map[i]; + SET_HARD_REG_BIT (OBJECT_CONFLICT_HARD_REGS (obj), regno); + SET_HARD_REG_BIT (OBJECT_TOTAL_CONFLICT_HARD_REGS (obj), regno); } - a = ira_curr_regno_allocno_map[regno]; - if (a == NULL) - return; - if ((p = ALLOCNO_LIVE_RANGES (a)) == NULL - || (p->finish != curr_point && p->finish + 1 != curr_point)) - ALLOCNO_LIVE_RANGES (a) - = ira_create_allocno_live_range (a, curr_point, -1, - ALLOCNO_LIVE_RANGES (a)); +} + +/* Process the death of hard register REGNO. This updates + hard_regs_live. */ +static void +make_hard_regno_dead (int regno) +{ + CLEAR_HARD_REG_BIT (hard_regs_live, regno); } -/* Update ALLOCNO_EXCESS_PRESSURE_POINTS_NUM for allocno A. */ +/* Record the birth of object OBJ. Set a bit for it in objects_live, + start a new live range for it if necessary and update hard register + conflicts. */ static void -update_allocno_pressure_excess_length (ira_allocno_t a) +make_object_born (ira_object_t obj) { + live_range_t lr = OBJECT_LIVE_RANGES (obj); + + sparseset_set_bit (objects_live, OBJECT_CONFLICT_ID (obj)); + IOR_HARD_REG_SET (OBJECT_CONFLICT_HARD_REGS (obj), hard_regs_live); + IOR_HARD_REG_SET (OBJECT_TOTAL_CONFLICT_HARD_REGS (obj), hard_regs_live); + + if (lr == NULL + || (lr->finish != curr_point && lr->finish + 1 != curr_point)) + ira_add_live_range_to_object (obj, curr_point, -1); +} + +/* Update ALLOCNO_EXCESS_PRESSURE_POINTS_NUM for the allocno + associated with object OBJ. */ +static void +update_allocno_pressure_excess_length (ira_object_t obj) +{ + ira_allocno_t a = OBJECT_ALLOCNO (obj); int start, i; enum reg_class cover_class, cl; - allocno_live_range_t p; + live_range_t p; cover_class = ALLOCNO_COVER_CLASS (a); for (i = 0; @@ -129,7 +144,7 @@ { if (high_pressure_start_point[cl] < 0) continue; - p = ALLOCNO_LIVE_RANGES (a); + p = OBJECT_LIVE_RANGES (obj); ira_assert (p != NULL); start = (high_pressure_start_point[cl] > p->start ? high_pressure_start_point[cl] : p->start); @@ -137,56 +152,39 @@ } } -/* Process the death of register REGNO. This updates hard_regs_live - or finishes the current live range for the allocno corresponding to - REGNO. */ +/* Process the death of object OBJ, which is associated with allocno + A. This finishes the current live range for it. */ static void -make_regno_dead (int regno) +make_object_dead (ira_object_t obj) { - ira_allocno_t a; - allocno_live_range_t p; + live_range_t lr; - if (regno < FIRST_PSEUDO_REGISTER) - { - CLEAR_HARD_REG_BIT (hard_regs_live, regno); - return; - } - a = ira_curr_regno_allocno_map[regno]; - if (a == NULL) - return; - p = ALLOCNO_LIVE_RANGES (a); - ira_assert (p != NULL); - p->finish = curr_point; - update_allocno_pressure_excess_length (a); + sparseset_clear_bit (objects_live, OBJECT_CONFLICT_ID (obj)); + lr = OBJECT_LIVE_RANGES (obj); + ira_assert (lr != NULL); + lr->finish = curr_point; + update_allocno_pressure_excess_length (obj); } /* The current register pressures for each cover class for the current basic block. */ static int curr_reg_pressure[N_REG_CLASSES]; -/* Mark allocno A as currently living and update current register - pressure, maximal register pressure for the current BB, start point - of the register pressure excess, and conflicting hard registers of - A. */ +/* Record that register pressure for COVER_CLASS increased by N + registers. Update the current register pressure, maximal register + pressure for the current BB and the start point of the register + pressure excess. */ static void -set_allocno_live (ira_allocno_t a) +inc_register_pressure (enum reg_class cover_class, int n) { int i; - enum reg_class cover_class, cl; + enum reg_class cl; - /* Invalidate because it is referenced. */ - allocno_saved_at_call[ALLOCNO_NUM (a)] = 0; - if (sparseset_bit_p (allocnos_live, ALLOCNO_NUM (a))) - return; - sparseset_set_bit (allocnos_live, ALLOCNO_NUM (a)); - IOR_HARD_REG_SET (ALLOCNO_CONFLICT_HARD_REGS (a), hard_regs_live); - IOR_HARD_REG_SET (ALLOCNO_TOTAL_CONFLICT_HARD_REGS (a), hard_regs_live); - cover_class = ALLOCNO_COVER_CLASS (a); for (i = 0; (cl = ira_reg_class_super_classes[cover_class][i]) != LIM_REG_CLASSES; i++) { - curr_reg_pressure[cl] += ira_reg_class_nregs[cl][ALLOCNO_MODE (a)]; + curr_reg_pressure[cl] += n; if (high_pressure_start_point[cl] < 0 && (curr_reg_pressure[cl] > ira_available_class_regs[cl])) high_pressure_start_point[cl] = curr_point; @@ -195,223 +193,316 @@ } } -/* Mark allocno A as currently not living and update current register - pressure, start point of the register pressure excess, and register - pressure excess length for living allocnos. */ +/* Record that register pressure for COVER_CLASS has decreased by + NREGS registers; update current register pressure, start point of + the register pressure excess, and register pressure excess length + for living allocnos. */ + static void -clear_allocno_live (ira_allocno_t a) +dec_register_pressure (enum reg_class cover_class, int nregs) { int i; unsigned int j; - enum reg_class cover_class, cl; - bool set_p; + enum reg_class cl; + bool set_p = false; - /* Invalidate because it is referenced. */ - allocno_saved_at_call[ALLOCNO_NUM (a)] = 0; - if (sparseset_bit_p (allocnos_live, ALLOCNO_NUM (a))) + for (i = 0; + (cl = ira_reg_class_super_classes[cover_class][i]) != LIM_REG_CLASSES; + i++) { - cover_class = ALLOCNO_COVER_CLASS (a); - set_p = false; + curr_reg_pressure[cl] -= nregs; + ira_assert (curr_reg_pressure[cl] >= 0); + if (high_pressure_start_point[cl] >= 0 + && curr_reg_pressure[cl] <= ira_available_class_regs[cl]) + set_p = true; + } + if (set_p) + { + EXECUTE_IF_SET_IN_SPARSESET (objects_live, j) + update_allocno_pressure_excess_length (ira_object_id_map[j]); for (i = 0; (cl = ira_reg_class_super_classes[cover_class][i]) != LIM_REG_CLASSES; i++) - { - curr_reg_pressure[cl] -= ira_reg_class_nregs[cl][ALLOCNO_MODE (a)]; - ira_assert (curr_reg_pressure[cl] >= 0); - if (high_pressure_start_point[cl] >= 0 - && curr_reg_pressure[cl] <= ira_available_class_regs[cl]) - set_p = true; - } - if (set_p) - { - EXECUTE_IF_SET_IN_SPARSESET (allocnos_live, j) - update_allocno_pressure_excess_length (ira_allocnos[j]); - for (i = 0; - (cl = ira_reg_class_super_classes[cover_class][i]) - != LIM_REG_CLASSES; - i++) - if (high_pressure_start_point[cl] >= 0 - && curr_reg_pressure[cl] <= ira_available_class_regs[cl]) - high_pressure_start_point[cl] = -1; + if (high_pressure_start_point[cl] >= 0 + && curr_reg_pressure[cl] <= ira_available_class_regs[cl]) + high_pressure_start_point[cl] = -1; + } +} + +/* Mark the pseudo register REGNO as live. Update all information about + live ranges and register pressure. */ +static void +mark_pseudo_regno_live (int regno) +{ + ira_allocno_t a = ira_curr_regno_allocno_map[regno]; + int i, n, nregs; + enum reg_class cl; + + if (a == NULL) + return; - } + /* Invalidate because it is referenced. */ + allocno_saved_at_call[ALLOCNO_NUM (a)] = 0; + + n = ALLOCNO_NUM_OBJECTS (a); + cl = ALLOCNO_COVER_CLASS (a); + nregs = ira_reg_class_nregs[cl][ALLOCNO_MODE (a)]; + if (n > 1) + { + /* We track every subobject separately. */ + gcc_assert (nregs == n); + nregs = 1; } - sparseset_clear_bit (allocnos_live, ALLOCNO_NUM (a)); + + for (i = 0; i < n; i++) + { + ira_object_t obj = ALLOCNO_OBJECT (a, i); + if (sparseset_bit_p (objects_live, OBJECT_CONFLICT_ID (obj))) + continue; + + inc_register_pressure (cl, nregs); + make_object_born (obj); + } } -/* Mark the register REG as live. Store a 1 in hard_regs_live or - allocnos_live for this register or the corresponding allocno, - record how many consecutive hardware registers it actually - needs. */ +/* Like mark_pseudo_regno_live, but try to only mark one subword of + the pseudo as live. SUBWORD indicates which; a value of 0 + indicates the low part. */ static void -mark_reg_live (rtx reg) +mark_pseudo_regno_subword_live (int regno, int subword) { - int i, regno; + ira_allocno_t a = ira_curr_regno_allocno_map[regno]; + int n, nregs; + enum reg_class cl; + ira_object_t obj; - gcc_assert (REG_P (reg)); - regno = REGNO (reg); + if (a == NULL) + return; - if (regno >= FIRST_PSEUDO_REGISTER) + /* Invalidate because it is referenced. */ + allocno_saved_at_call[ALLOCNO_NUM (a)] = 0; + + n = ALLOCNO_NUM_OBJECTS (a); + if (n == 1) { - ira_allocno_t a = ira_curr_regno_allocno_map[regno]; + mark_pseudo_regno_live (regno); + return; + } + + cl = ALLOCNO_COVER_CLASS (a); + nregs = ira_reg_class_nregs[cl][ALLOCNO_MODE (a)]; + gcc_assert (nregs == n); + obj = ALLOCNO_OBJECT (a, subword); + + if (sparseset_bit_p (objects_live, OBJECT_CONFLICT_ID (obj))) + return; - if (a != NULL) - { - if (sparseset_bit_p (allocnos_live, ALLOCNO_NUM (a))) - { - /* Invalidate because it is referenced. */ - allocno_saved_at_call[ALLOCNO_NUM (a)] = 0; - return; - } - set_allocno_live (a); - } - make_regno_born (regno); - } - else if (! TEST_HARD_REG_BIT (ira_no_alloc_regs, regno)) + inc_register_pressure (cl, nregs); + make_object_born (obj); +} + +/* Mark the register REG as live. Store a 1 in hard_regs_live for + this register, record how many consecutive hardware registers it + actually needs. */ +static void +mark_hard_reg_live (rtx reg) +{ + int regno = REGNO (reg); + + if (! TEST_HARD_REG_BIT (ira_no_alloc_regs, regno)) { int last = regno + hard_regno_nregs[regno][GET_MODE (reg)]; - enum reg_class cover_class, cl; while (regno < last) { if (! TEST_HARD_REG_BIT (hard_regs_live, regno) && ! TEST_HARD_REG_BIT (eliminable_regset, regno)) { - cover_class = ira_hard_regno_cover_class[regno]; - for (i = 0; - (cl = ira_reg_class_super_classes[cover_class][i]) - != LIM_REG_CLASSES; - i++) - { - curr_reg_pressure[cl]++; - if (high_pressure_start_point[cl] < 0 - && (curr_reg_pressure[cl] - > ira_available_class_regs[cl])) - high_pressure_start_point[cl] = curr_point; - } - make_regno_born (regno); - for (i = 0; - (cl = ira_reg_class_super_classes[cover_class][i]) - != LIM_REG_CLASSES; - i++) - { - if (curr_bb_node->reg_pressure[cl] < curr_reg_pressure[cl]) - curr_bb_node->reg_pressure[cl] = curr_reg_pressure[cl]; - } + enum reg_class cover_class = ira_hard_regno_cover_class[regno]; + inc_register_pressure (cover_class, 1); + make_hard_regno_born (regno); } regno++; } } } +/* Mark a pseudo, or one of its subwords, as live. REGNO is the pseudo's + register number; ORIG_REG is the access in the insn, which may be a + subreg. */ +static void +mark_pseudo_reg_live (rtx orig_reg, unsigned regno) +{ + if (df_read_modify_subreg_p (orig_reg)) + { + mark_pseudo_regno_subword_live (regno, + subreg_lowpart_p (orig_reg) ? 0 : 1); + } + else + mark_pseudo_regno_live (regno); +} + /* Mark the register referenced by use or def REF as live. */ static void mark_ref_live (df_ref ref) { - rtx reg; + rtx reg = DF_REF_REG (ref); + rtx orig_reg = reg; - reg = DF_REF_REG (ref); if (GET_CODE (reg) == SUBREG) reg = SUBREG_REG (reg); - mark_reg_live (reg); + + if (REGNO (reg) >= FIRST_PSEUDO_REGISTER) + mark_pseudo_reg_live (orig_reg, REGNO (reg)); + else + mark_hard_reg_live (reg); } -/* Mark the register REG as dead. Store a 0 in hard_regs_live or - allocnos_live for the register. */ +/* Mark the pseudo register REGNO as dead. Update all information about + live ranges and register pressure. */ static void -mark_reg_dead (rtx reg) +mark_pseudo_regno_dead (int regno) { - int regno; + ira_allocno_t a = ira_curr_regno_allocno_map[regno]; + int n, i, nregs; + enum reg_class cl; + + if (a == NULL) + return; + + /* Invalidate because it is referenced. */ + allocno_saved_at_call[ALLOCNO_NUM (a)] = 0; - gcc_assert (REG_P (reg)); - regno = REGNO (reg); + n = ALLOCNO_NUM_OBJECTS (a); + cl = ALLOCNO_COVER_CLASS (a); + nregs = ira_reg_class_nregs[cl][ALLOCNO_MODE (a)]; + if (n > 1) + { + /* We track every subobject separately. */ + gcc_assert (nregs == n); + nregs = 1; + } + for (i = 0; i < n; i++) + { + ira_object_t obj = ALLOCNO_OBJECT (a, i); + if (!sparseset_bit_p (objects_live, OBJECT_CONFLICT_ID (obj))) + continue; - if (regno >= FIRST_PSEUDO_REGISTER) - { - ira_allocno_t a = ira_curr_regno_allocno_map[regno]; + dec_register_pressure (cl, nregs); + make_object_dead (obj); + } +} - if (a != NULL) - { - if (! sparseset_bit_p (allocnos_live, ALLOCNO_NUM (a))) - { - /* Invalidate because it is referenced. */ - allocno_saved_at_call[ALLOCNO_NUM (a)] = 0; - return; - } - clear_allocno_live (a); - } - make_regno_dead (regno); - } - else if (! TEST_HARD_REG_BIT (ira_no_alloc_regs, regno)) +/* Like mark_pseudo_regno_dead, but called when we know that only part of the + register dies. SUBWORD indicates which; a value of 0 indicates the low part. */ +static void +mark_pseudo_regno_subword_dead (int regno, int subword) +{ + ira_allocno_t a = ira_curr_regno_allocno_map[regno]; + int n, nregs; + enum reg_class cl; + ira_object_t obj; + + if (a == NULL) + return; + + /* Invalidate because it is referenced. */ + allocno_saved_at_call[ALLOCNO_NUM (a)] = 0; + + n = ALLOCNO_NUM_OBJECTS (a); + if (n == 1) + /* The allocno as a whole doesn't die in this case. */ + return; + + cl = ALLOCNO_COVER_CLASS (a); + nregs = ira_reg_class_nregs[cl][ALLOCNO_MODE (a)]; + gcc_assert (nregs == n); + + obj = ALLOCNO_OBJECT (a, subword); + if (!sparseset_bit_p (objects_live, OBJECT_CONFLICT_ID (obj))) + return; + + dec_register_pressure (cl, 1); + make_object_dead (obj); +} + +/* Mark the hard register REG as dead. Store a 0 in hard_regs_live for the + register. */ +static void +mark_hard_reg_dead (rtx reg) +{ + int regno = REGNO (reg); + + if (! TEST_HARD_REG_BIT (ira_no_alloc_regs, regno)) { - int i; - unsigned int j; int last = regno + hard_regno_nregs[regno][GET_MODE (reg)]; - enum reg_class cover_class, cl; - bool set_p; while (regno < last) { if (TEST_HARD_REG_BIT (hard_regs_live, regno)) { - set_p = false; - cover_class = ira_hard_regno_cover_class[regno]; - for (i = 0; - (cl = ira_reg_class_super_classes[cover_class][i]) - != LIM_REG_CLASSES; - i++) - { - curr_reg_pressure[cl]--; - if (high_pressure_start_point[cl] >= 0 - && curr_reg_pressure[cl] <= ira_available_class_regs[cl]) - set_p = true; - ira_assert (curr_reg_pressure[cl] >= 0); - } - if (set_p) - { - EXECUTE_IF_SET_IN_SPARSESET (allocnos_live, j) - update_allocno_pressure_excess_length (ira_allocnos[j]); - for (i = 0; - (cl = ira_reg_class_super_classes[cover_class][i]) - != LIM_REG_CLASSES; - i++) - if (high_pressure_start_point[cl] >= 0 - && (curr_reg_pressure[cl] - <= ira_available_class_regs[cl])) - high_pressure_start_point[cl] = -1; - } - make_regno_dead (regno); + enum reg_class cover_class = ira_hard_regno_cover_class[regno]; + dec_register_pressure (cover_class, 1); + make_hard_regno_dead (regno); } regno++; } } } +/* Mark a pseudo, or one of its subwords, as dead. REGNO is the pseudo's + register number; ORIG_REG is the access in the insn, which may be a + subreg. */ +static void +mark_pseudo_reg_dead (rtx orig_reg, unsigned regno) +{ + if (df_read_modify_subreg_p (orig_reg)) + { + mark_pseudo_regno_subword_dead (regno, + subreg_lowpart_p (orig_reg) ? 0 : 1); + } + else + mark_pseudo_regno_dead (regno); +} + /* Mark the register referenced by definition DEF as dead, if the definition is a total one. */ static void mark_ref_dead (df_ref def) { - rtx reg; + rtx reg = DF_REF_REG (def); + rtx orig_reg = reg; - if (DF_REF_FLAGS_IS_SET (def, DF_REF_PARTIAL) - || DF_REF_FLAGS_IS_SET (def, DF_REF_CONDITIONAL)) + if (DF_REF_FLAGS_IS_SET (def, DF_REF_CONDITIONAL)) return; - reg = DF_REF_REG (def); if (GET_CODE (reg) == SUBREG) reg = SUBREG_REG (reg); - mark_reg_dead (reg); + + if (DF_REF_FLAGS_IS_SET (def, DF_REF_PARTIAL) + && (GET_CODE (orig_reg) != SUBREG + || REGNO (reg) < FIRST_PSEUDO_REGISTER + || !df_read_modify_subreg_p (orig_reg))) + return; + + if (REGNO (reg) >= FIRST_PSEUDO_REGISTER) + mark_pseudo_reg_dead (orig_reg, REGNO (reg)); + else + mark_hard_reg_dead (reg); } -/* Make pseudo REG conflicting with pseudo DREG, if the 1st pseudo - class is intersected with class CL. Advance the current program - point before making the conflict if ADVANCE_P. Return TRUE if we - will need to advance the current program point. */ +/* If REG is a pseudo or a subreg of it, and the class of its allocno + intersects CL, make a conflict with pseudo DREG. ORIG_DREG is the + rtx actually accessed, it may be indentical to DREG or a subreg of it. + Advance the current program point before making the conflict if + ADVANCE_P. Return TRUE if we will need to advance the current + program point. */ static bool -make_pseudo_conflict (rtx reg, enum reg_class cl, rtx dreg, bool advance_p) +make_pseudo_conflict (rtx reg, enum reg_class cl, rtx dreg, rtx orig_dreg, + bool advance_p) { + rtx orig_reg = reg; ira_allocno_t a; if (GET_CODE (reg) == SUBREG) @@ -427,29 +518,31 @@ if (advance_p) curr_point++; - mark_reg_live (reg); - mark_reg_live (dreg); - mark_reg_dead (reg); - mark_reg_dead (dreg); + mark_pseudo_reg_live (orig_reg, REGNO (reg)); + mark_pseudo_reg_live (orig_dreg, REGNO (dreg)); + mark_pseudo_reg_dead (orig_reg, REGNO (reg)); + mark_pseudo_reg_dead (orig_dreg, REGNO (dreg)); return false; } /* Check and make if necessary conflicts for pseudo DREG of class DEF_CL of the current insn with input operand USE of class USE_CL. - Advance the current program point before making the conflict if - ADVANCE_P. Return TRUE if we will need to advance the current - program point. */ + ORIG_DREG is the rtx actually accessed, it may be indentical to + DREG or a subreg of it. Advance the current program point before + making the conflict if ADVANCE_P. Return TRUE if we will need to + advance the current program point. */ static bool -check_and_make_def_use_conflict (rtx dreg, enum reg_class def_cl, - int use, enum reg_class use_cl, - bool advance_p) +check_and_make_def_use_conflict (rtx dreg, rtx orig_dreg, + enum reg_class def_cl, int use, + enum reg_class use_cl, bool advance_p) { if (! reg_classes_intersect_p (def_cl, use_cl)) return advance_p; advance_p = make_pseudo_conflict (recog_data.operand[use], - use_cl, dreg, advance_p); + use_cl, dreg, orig_dreg, advance_p); + /* Reload may end up swapping commutative operands, so you have to take both orderings into account. The constraints for the two operands can be completely @@ -460,12 +553,12 @@ && recog_data.constraints[use][0] == '%') advance_p = make_pseudo_conflict (recog_data.operand[use + 1], - use_cl, dreg, advance_p); + use_cl, dreg, orig_dreg, advance_p); if (use >= 1 && recog_data.constraints[use - 1][0] == '%') advance_p = make_pseudo_conflict (recog_data.operand[use - 1], - use_cl, dreg, advance_p); + use_cl, dreg, orig_dreg, advance_p); return advance_p; } @@ -480,6 +573,7 @@ enum reg_class use_cl, acl; bool advance_p; rtx dreg = recog_data.operand[def]; + rtx orig_dreg = dreg; if (def_cl == NO_REGS) return; @@ -511,7 +605,7 @@ /* If there's any alternative that allows USE to match DEF, do not record a conflict. If that causes us to create an invalid - instruction due to the earlyclobber, reload must fix it up. */ + instruction due to the earlyclobber, reload must fix it up. */ for (alt1 = 0; alt1 < recog_data.n_alternatives; alt1++) if (recog_op_alt[use][alt1].matches == def || (use < recog_data.n_operands - 1 @@ -525,8 +619,8 @@ if (alt1 < recog_data.n_alternatives) continue; - advance_p = check_and_make_def_use_conflict (dreg, def_cl, use, - use_cl, advance_p); + advance_p = check_and_make_def_use_conflict (dreg, orig_dreg, def_cl, + use, use_cl, advance_p); if ((use_match = recog_op_alt[use][alt].matches) >= 0) { @@ -537,8 +631,8 @@ use_cl = ALL_REGS; else use_cl = recog_op_alt[use_match][alt].cl; - advance_p = check_and_make_def_use_conflict (dreg, def_cl, use, - use_cl, advance_p); + advance_p = check_and_make_def_use_conflict (dreg, orig_dreg, def_cl, + use, use_cl, advance_p); } } } @@ -823,7 +917,7 @@ static void process_single_reg_class_operands (bool in_p, int freq) { - int i, regno, cost; + int i, regno; unsigned int px; enum reg_class cl; rtx operand; @@ -850,46 +944,61 @@ if (REG_P (operand) && (regno = REGNO (operand)) >= FIRST_PSEUDO_REGISTER) { - enum machine_mode mode; enum reg_class cover_class; operand_a = ira_curr_regno_allocno_map[regno]; - mode = ALLOCNO_MODE (operand_a); cover_class = ALLOCNO_COVER_CLASS (operand_a); if (ira_class_subset_p[cl][cover_class] - && ira_class_hard_regs_num[cl] != 0 - && (ira_class_hard_reg_index[cover_class] - [ira_class_hard_regs[cl][0]]) >= 0 - && reg_class_size[cl] <= (unsigned) CLASS_MAX_NREGS (cl, mode)) + && ira_class_hard_regs_num[cl] != 0) { - int i, size; - cost - = (freq - * (in_p - ? ira_get_register_move_cost (mode, cover_class, cl) - : ira_get_register_move_cost (mode, cl, cover_class))); - ira_allocate_and_set_costs - (&ALLOCNO_CONFLICT_HARD_REG_COSTS (operand_a), cover_class, 0); - size = ira_reg_class_nregs[cover_class][mode]; - for (i = 0; i < size; i++) - ALLOCNO_CONFLICT_HARD_REG_COSTS (operand_a) - [ira_class_hard_reg_index - [cover_class][ira_class_hard_regs[cl][i]]] - -= cost; + /* View the desired allocation of OPERAND as: + + (REG:YMODE YREGNO), + + a simplification of: + + (subreg:YMODE (reg:XMODE XREGNO) OFFSET). */ + enum machine_mode ymode, xmode; + int xregno, yregno; + HOST_WIDE_INT offset; + + xmode = recog_data.operand_mode[i]; + xregno = ira_class_hard_regs[cl][0]; + ymode = ALLOCNO_MODE (operand_a); + offset = subreg_lowpart_offset (ymode, xmode); + yregno = simplify_subreg_regno (xregno, xmode, offset, ymode); + if (yregno >= 0 + && ira_class_hard_reg_index[cover_class][yregno] >= 0) + { + int cost; + + ira_allocate_and_set_costs + (&ALLOCNO_CONFLICT_HARD_REG_COSTS (operand_a), + cover_class, 0); + cost + = (freq + * (in_p + ? ira_get_register_move_cost (xmode, cover_class, cl) + : ira_get_register_move_cost (xmode, cl, + cover_class))); + ALLOCNO_CONFLICT_HARD_REG_COSTS (operand_a) + [ira_class_hard_reg_index[cover_class][yregno]] -= cost; + } } } - EXECUTE_IF_SET_IN_SPARSESET (allocnos_live, px) + EXECUTE_IF_SET_IN_SPARSESET (objects_live, px) { - a = ira_allocnos[px]; + ira_object_t obj = ira_object_id_map[px]; + a = OBJECT_ALLOCNO (obj); if (a != operand_a) { /* We could increase costs of A instead of making it conflicting with the hard register. But it works worse because it will be spilled in reload in anyway. */ - IOR_HARD_REG_SET (ALLOCNO_CONFLICT_HARD_REGS (a), + IOR_HARD_REG_SET (OBJECT_CONFLICT_HARD_REGS (obj), reg_class_contents[cl]); - IOR_HARD_REG_SET (ALLOCNO_TOTAL_CONFLICT_HARD_REGS (a), + IOR_HARD_REG_SET (OBJECT_TOTAL_CONFLICT_HARD_REGS (obj), reg_class_contents[cl]); } } @@ -938,7 +1047,7 @@ } curr_bb_node = loop_tree_node; reg_live_out = DF_LR_OUT (bb); - sparseset_clear (allocnos_live); + sparseset_clear (objects_live); REG_SET_TO_HARD_REG_SET (hard_regs_live, reg_live_out); AND_COMPL_HARD_REG_SET (hard_regs_live, eliminable_regset); AND_COMPL_HARD_REG_SET (hard_regs_live, ira_no_alloc_regs); @@ -961,15 +1070,7 @@ } } EXECUTE_IF_SET_IN_BITMAP (reg_live_out, FIRST_PSEUDO_REGISTER, j, bi) - { - ira_allocno_t a = ira_curr_regno_allocno_map[j]; - - if (a == NULL) - continue; - ira_assert (! sparseset_bit_p (allocnos_live, ALLOCNO_NUM (a))); - set_allocno_live (a); - make_regno_born (j); - } + mark_pseudo_regno_live (j); freq = REG_FREQ_FROM_BB (bb); if (freq == 0) @@ -1060,12 +1161,37 @@ if (call_p) { last_call_num++; + sparseset_clear (allocnos_processed); /* The current set of live allocnos are live across the call. */ - EXECUTE_IF_SET_IN_SPARSESET (allocnos_live, i) + EXECUTE_IF_SET_IN_SPARSESET (objects_live, i) { - ira_allocno_t a = ira_allocnos[i]; + ira_object_t obj = ira_object_id_map[i]; + ira_allocno_t a = OBJECT_ALLOCNO (obj); + int num = ALLOCNO_NUM (a); - if (allocno_saved_at_call[i] != last_call_num) + /* Don't allocate allocnos that cross setjmps or any + call, if this function receives a nonlocal + goto. */ + if (cfun->has_nonlocal_label + || find_reg_note (insn, REG_SETJMP, + NULL_RTX) != NULL_RTX) + { + SET_HARD_REG_SET (OBJECT_CONFLICT_HARD_REGS (obj)); + SET_HARD_REG_SET (OBJECT_TOTAL_CONFLICT_HARD_REGS (obj)); + } + if (can_throw_internal (insn)) + { + IOR_HARD_REG_SET (OBJECT_CONFLICT_HARD_REGS (obj), + call_used_reg_set); + IOR_HARD_REG_SET (OBJECT_TOTAL_CONFLICT_HARD_REGS (obj), + call_used_reg_set); + } + + if (sparseset_bit_p (allocnos_processed, num)) + continue; + sparseset_set_bit (allocnos_processed, num); + + if (allocno_saved_at_call[num] != last_call_num) /* Here we are mimicking caller-save.c behaviour which does not save hard register at a call if it was saved on previous call in the same basic @@ -1073,25 +1199,8 @@ between the two calls. */ ALLOCNO_CALL_FREQ (a) += freq; /* Mark it as saved at the next call. */ - allocno_saved_at_call[i] = last_call_num + 1; + allocno_saved_at_call[num] = last_call_num + 1; ALLOCNO_CALLS_CROSSED_NUM (a)++; - /* Don't allocate allocnos that cross setjmps or any - call, if this function receives a nonlocal - goto. */ - if (cfun->has_nonlocal_label - || find_reg_note (insn, REG_SETJMP, - NULL_RTX) != NULL_RTX) - { - SET_HARD_REG_SET (ALLOCNO_CONFLICT_HARD_REGS (a)); - SET_HARD_REG_SET (ALLOCNO_TOTAL_CONFLICT_HARD_REGS (a)); - } - if (can_throw_internal (insn)) - { - IOR_HARD_REG_SET (ALLOCNO_TOTAL_CONFLICT_HARD_REGS (a), - call_used_reg_set); - IOR_HARD_REG_SET (ALLOCNO_CONFLICT_HARD_REGS (a), - call_used_reg_set); - } } } @@ -1137,7 +1246,7 @@ unsigned int regno = EH_RETURN_DATA_REGNO (j); if (regno == INVALID_REGNUM) break; - make_regno_born (regno); + make_hard_regno_born (regno); } #endif @@ -1149,13 +1258,14 @@ if (bb_has_abnormal_pred (bb)) { #ifdef STACK_REGS - EXECUTE_IF_SET_IN_SPARSESET (allocnos_live, px) + EXECUTE_IF_SET_IN_SPARSESET (objects_live, px) { - ALLOCNO_NO_STACK_REG_P (ira_allocnos[px]) = true; - ALLOCNO_TOTAL_NO_STACK_REG_P (ira_allocnos[px]) = true; + ira_allocno_t a = OBJECT_ALLOCNO (ira_object_id_map[px]); + ALLOCNO_NO_STACK_REG_P (a) = true; + ALLOCNO_TOTAL_NO_STACK_REG_P (a) = true; } for (px = FIRST_STACK_REG; px <= LAST_STACK_REG; px++) - make_regno_born (px); + make_hard_regno_born (px); #endif /* No need to record conflicts for call clobbered regs if we have nonlocal labels around, as we don't ever try to @@ -1163,13 +1273,11 @@ if (!cfun->has_nonlocal_label && bb_has_abnormal_call_pred (bb)) for (px = 0; px < FIRST_PSEUDO_REGISTER; px++) if (call_used_regs[px]) - make_regno_born (px); + make_hard_regno_born (px); } - EXECUTE_IF_SET_IN_SPARSESET (allocnos_live, i) - { - make_regno_dead (ALLOCNO_REGNO (ira_allocnos[i])); - } + EXECUTE_IF_SET_IN_SPARSESET (objects_live, i) + make_object_dead (ira_object_id_map[i]); curr_point++; @@ -1193,30 +1301,24 @@ static void create_start_finish_chains (void) { - ira_allocno_t a; - ira_allocno_iterator ai; - allocno_live_range_t r; + ira_object_t obj; + ira_object_iterator oi; + live_range_t r; ira_start_point_ranges - = (allocno_live_range_t *) ira_allocate (ira_max_point - * sizeof (allocno_live_range_t)); - memset (ira_start_point_ranges, 0, - ira_max_point * sizeof (allocno_live_range_t)); + = (live_range_t *) ira_allocate (ira_max_point * sizeof (live_range_t)); + memset (ira_start_point_ranges, 0, ira_max_point * sizeof (live_range_t)); ira_finish_point_ranges - = (allocno_live_range_t *) ira_allocate (ira_max_point - * sizeof (allocno_live_range_t)); - memset (ira_finish_point_ranges, 0, - ira_max_point * sizeof (allocno_live_range_t)); - FOR_EACH_ALLOCNO (a, ai) - { - for (r = ALLOCNO_LIVE_RANGES (a); r != NULL; r = r->next) - { - r->start_next = ira_start_point_ranges[r->start]; - ira_start_point_ranges[r->start] = r; - r->finish_next = ira_finish_point_ranges[r->finish]; + = (live_range_t *) ira_allocate (ira_max_point * sizeof (live_range_t)); + memset (ira_finish_point_ranges, 0, ira_max_point * sizeof (live_range_t)); + FOR_EACH_OBJECT (obj, oi) + for (r = OBJECT_LIVE_RANGES (obj); r != NULL; r = r->next) + { + r->start_next = ira_start_point_ranges[r->start]; + ira_start_point_ranges[r->start] = r; + r->finish_next = ira_finish_point_ranges[r->finish]; ira_finish_point_ranges[r->finish] = r; - } - } + } } /* Rebuild IRA_START_POINT_RANGES and IRA_FINISH_POINT_RANGES after @@ -1238,47 +1340,64 @@ unsigned i; int n; int *map; - ira_allocno_t a; - ira_allocno_iterator ai; - allocno_live_range_t r; - bitmap born_or_died; - bitmap_iterator bi; + ira_object_t obj; + ira_object_iterator oi; + live_range_t r; + sbitmap born_or_dead, born, dead; + sbitmap_iterator sbi; + bool born_p, dead_p, prev_born_p, prev_dead_p; + + born = sbitmap_alloc (ira_max_point); + dead = sbitmap_alloc (ira_max_point); + sbitmap_zero (born); + sbitmap_zero (dead); + FOR_EACH_OBJECT (obj, oi) + for (r = OBJECT_LIVE_RANGES (obj); r != NULL; r = r->next) + { + ira_assert (r->start <= r->finish); + SET_BIT (born, r->start); + SET_BIT (dead, r->finish); + } - born_or_died = ira_allocate_bitmap (); - FOR_EACH_ALLOCNO (a, ai) + born_or_dead = sbitmap_alloc (ira_max_point); + sbitmap_a_or_b (born_or_dead, born, dead); + map = (int *) ira_allocate (sizeof (int) * ira_max_point); + n = -1; + prev_born_p = prev_dead_p = false; + EXECUTE_IF_SET_IN_SBITMAP (born_or_dead, 0, i, sbi) { - for (r = ALLOCNO_LIVE_RANGES (a); r != NULL; r = r->next) - { - ira_assert (r->start <= r->finish); - bitmap_set_bit (born_or_died, r->start); - bitmap_set_bit (born_or_died, r->finish); - } + born_p = TEST_BIT (born, i); + dead_p = TEST_BIT (dead, i); + if ((prev_born_p && ! prev_dead_p && born_p && ! dead_p) + || (prev_dead_p && ! prev_born_p && dead_p && ! born_p)) + map[i] = n; + else + map[i] = ++n; + prev_born_p = born_p; + prev_dead_p = dead_p; } - map = (int *) ira_allocate (sizeof (int) * ira_max_point); - n = 0; - EXECUTE_IF_SET_IN_BITMAP(born_or_died, 0, i, bi) - { - map[i] = n++; - } - ira_free_bitmap (born_or_died); + sbitmap_free (born_or_dead); + sbitmap_free (born); + sbitmap_free (dead); + n++; if (internal_flag_ira_verbose > 1 && ira_dump_file != NULL) fprintf (ira_dump_file, "Compressing live ranges: from %d to %d - %d%%\n", ira_max_point, n, 100 * n / ira_max_point); ira_max_point = n; - FOR_EACH_ALLOCNO (a, ai) - { - for (r = ALLOCNO_LIVE_RANGES (a); r != NULL; r = r->next) - { - r->start = map[r->start]; - r->finish = map[r->finish]; - } - } + + FOR_EACH_OBJECT (obj, oi) + for (r = OBJECT_LIVE_RANGES (obj); r != NULL; r = r->next) + { + r->start = map[r->start]; + r->finish = map[r->finish]; + } + ira_free (map); } /* Print live ranges R to file F. */ void -ira_print_live_range_list (FILE *f, allocno_live_range_t r) +ira_print_live_range_list (FILE *f, live_range_t r) { for (; r != NULL; r = r->next) fprintf (f, " [%d..%d]", r->start, r->finish); @@ -1287,17 +1406,32 @@ /* Print live ranges R to stderr. */ void -ira_debug_live_range_list (allocno_live_range_t r) +ira_debug_live_range_list (live_range_t r) { ira_print_live_range_list (stderr, r); } +/* Print live ranges of object OBJ to file F. */ +static void +print_object_live_ranges (FILE *f, ira_object_t obj) +{ + ira_print_live_range_list (f, OBJECT_LIVE_RANGES (obj)); +} + /* Print live ranges of allocno A to file F. */ static void print_allocno_live_ranges (FILE *f, ira_allocno_t a) { - fprintf (f, " a%d(r%d):", ALLOCNO_NUM (a), ALLOCNO_REGNO (a)); - ira_print_live_range_list (f, ALLOCNO_LIVE_RANGES (a)); + int n = ALLOCNO_NUM_OBJECTS (a); + int i; + for (i = 0; i < n; i++) + { + fprintf (f, " a%d(r%d", ALLOCNO_NUM (a), ALLOCNO_REGNO (a)); + if (n > 1) + fprintf (f, " [%d]", i); + fprintf (f, "):"); + print_object_live_ranges (f, ALLOCNO_OBJECT (a, i)); + } } /* Print live ranges of allocno A to stderr. */ @@ -1326,12 +1460,13 @@ } /* The main entry function creates live ranges, set up - CONFLICT_HARD_REGS and TOTAL_CONFLICT_HARD_REGS for allocnos, and + CONFLICT_HARD_REGS and TOTAL_CONFLICT_HARD_REGS for objects, and calculate register pressure info. */ void ira_create_allocno_live_ranges (void) { - allocnos_live = sparseset_alloc (ira_allocnos_num); + objects_live = sparseset_alloc (ira_objects_num); + allocnos_processed = sparseset_alloc (ira_allocnos_num); curr_point = 0; last_call_num = 0; allocno_saved_at_call @@ -1345,7 +1480,8 @@ print_live_ranges (ira_dump_file); /* Clean up. */ ira_free (allocno_saved_at_call); - sparseset_free (allocnos_live); + sparseset_free (objects_live); + sparseset_free (allocnos_processed); } /* Compress allocno live ranges. */