comparison gcc/loop-invariant.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
comparison
equal deleted inserted replaced
65:65488c3d617d 67:f6334be47118
534 unsigned i; 534 unsigned i;
535 struct invariant *inv; 535 struct invariant *inv;
536 htab_t eq = htab_create (VEC_length (invariant_p, invariants), 536 htab_t eq = htab_create (VEC_length (invariant_p, invariants),
537 hash_invariant_expr, eq_invariant_expr, free); 537 hash_invariant_expr, eq_invariant_expr, free);
538 538
539 for (i = 0; VEC_iterate (invariant_p, invariants, i, inv); i++) 539 FOR_EACH_VEC_ELT (invariant_p, invariants, i, inv)
540 find_identical_invariants (eq, inv); 540 find_identical_invariants (eq, inv);
541 541
542 htab_delete (eq); 542 htab_delete (eq);
543 } 543 }
544 544
1171 } 1171 }
1172 1172
1173 /* Calculates gain for eliminating invariant INV. REGS_USED is the number 1173 /* Calculates gain for eliminating invariant INV. REGS_USED is the number
1174 of registers used in the loop, NEW_REGS is the number of new variables 1174 of registers used in the loop, NEW_REGS is the number of new variables
1175 already added due to the invariant motion. The number of registers needed 1175 already added due to the invariant motion. The number of registers needed
1176 for it is stored in *REGS_NEEDED. */ 1176 for it is stored in *REGS_NEEDED. SPEED and CALL_P are flags passed
1177 through to estimate_reg_pressure_cost. */
1177 1178
1178 static int 1179 static int
1179 gain_for_invariant (struct invariant *inv, unsigned *regs_needed, 1180 gain_for_invariant (struct invariant *inv, unsigned *regs_needed,
1180 unsigned *new_regs, unsigned regs_used, bool speed) 1181 unsigned *new_regs, unsigned regs_used,
1182 bool speed, bool call_p)
1181 { 1183 {
1182 int comp_cost, size_cost; 1184 int comp_cost, size_cost;
1183 1185
1184 actual_stamp++; 1186 actual_stamp++;
1185 1187
1186 get_inv_cost (inv, &comp_cost, regs_needed); 1188 get_inv_cost (inv, &comp_cost, regs_needed);
1187 1189
1188 if (! flag_ira_loop_pressure) 1190 if (! flag_ira_loop_pressure)
1189 { 1191 {
1190 size_cost = (estimate_reg_pressure_cost (new_regs[0] + regs_needed[0], 1192 size_cost = (estimate_reg_pressure_cost (new_regs[0] + regs_needed[0],
1191 regs_used, speed) 1193 regs_used, speed, call_p)
1192 - estimate_reg_pressure_cost (new_regs[0], 1194 - estimate_reg_pressure_cost (new_regs[0],
1193 regs_used, speed)); 1195 regs_used, speed, call_p));
1194 } 1196 }
1195 else 1197 else
1196 { 1198 {
1197 int i; 1199 int i;
1198 enum reg_class cover_class; 1200 enum reg_class cover_class;
1243 NEW_REGS is the number of new variables already added due to invariant 1245 NEW_REGS is the number of new variables already added due to invariant
1244 motion. */ 1246 motion. */
1245 1247
1246 static int 1248 static int
1247 best_gain_for_invariant (struct invariant **best, unsigned *regs_needed, 1249 best_gain_for_invariant (struct invariant **best, unsigned *regs_needed,
1248 unsigned *new_regs, unsigned regs_used, bool speed) 1250 unsigned *new_regs, unsigned regs_used,
1251 bool speed, bool call_p)
1249 { 1252 {
1250 struct invariant *inv; 1253 struct invariant *inv;
1251 int i, gain = 0, again; 1254 int i, gain = 0, again;
1252 unsigned aregs_needed[N_REG_CLASSES], invno; 1255 unsigned aregs_needed[N_REG_CLASSES], invno;
1253 1256
1254 for (invno = 0; VEC_iterate (invariant_p, invariants, invno, inv); invno++) 1257 FOR_EACH_VEC_ELT (invariant_p, invariants, invno, inv)
1255 { 1258 {
1256 if (inv->move) 1259 if (inv->move)
1257 continue; 1260 continue;
1258 1261
1259 /* Only consider the "representatives" of equivalent invariants. */ 1262 /* Only consider the "representatives" of equivalent invariants. */
1260 if (inv->eqto != inv->invno) 1263 if (inv->eqto != inv->invno)
1261 continue; 1264 continue;
1262 1265
1263 again = gain_for_invariant (inv, aregs_needed, new_regs, regs_used, 1266 again = gain_for_invariant (inv, aregs_needed, new_regs, regs_used,
1264 speed); 1267 speed, call_p);
1265 if (again > gain) 1268 if (again > gain)
1266 { 1269 {
1267 gain = again; 1270 gain = again;
1268 *best = inv; 1271 *best = inv;
1269 if (! flag_ira_loop_pressure) 1272 if (! flag_ira_loop_pressure)
1312 } 1315 }
1313 1316
1314 /* Determines which invariants to move. */ 1317 /* Determines which invariants to move. */
1315 1318
1316 static void 1319 static void
1317 find_invariants_to_move (bool speed) 1320 find_invariants_to_move (bool speed, bool call_p)
1318 { 1321 {
1319 int gain; 1322 int gain;
1320 unsigned i, regs_used, regs_needed[N_REG_CLASSES], new_regs[N_REG_CLASSES]; 1323 unsigned i, regs_used, regs_needed[N_REG_CLASSES], new_regs[N_REG_CLASSES];
1321 struct invariant *inv = NULL; 1324 struct invariant *inv = NULL;
1322 1325
1351 { 1354 {
1352 for (i = 0; (int) i < ira_reg_class_cover_size; i++) 1355 for (i = 0; (int) i < ira_reg_class_cover_size; i++)
1353 new_regs[ira_reg_class_cover[i]] = 0; 1356 new_regs[ira_reg_class_cover[i]] = 0;
1354 } 1357 }
1355 while ((gain = best_gain_for_invariant (&inv, regs_needed, 1358 while ((gain = best_gain_for_invariant (&inv, regs_needed,
1356 new_regs, regs_used, speed)) > 0) 1359 new_regs, regs_used,
1360 speed, call_p)) > 0)
1357 { 1361 {
1358 set_move_mark (inv->invno, gain); 1362 set_move_mark (inv->invno, gain);
1359 if (! flag_ira_loop_pressure) 1363 if (! flag_ira_loop_pressure)
1360 new_regs[0] += regs_needed[0]; 1364 new_regs[0] += regs_needed[0];
1361 else 1365 else
1502 move_invariants (struct loop *loop) 1506 move_invariants (struct loop *loop)
1503 { 1507 {
1504 struct invariant *inv; 1508 struct invariant *inv;
1505 unsigned i; 1509 unsigned i;
1506 1510
1507 for (i = 0; VEC_iterate (invariant_p, invariants, i, inv); i++) 1511 FOR_EACH_VEC_ELT (invariant_p, invariants, i, inv)
1508 move_invariant_reg (loop, i); 1512 move_invariant_reg (loop, i);
1509 if (flag_ira_loop_pressure && resize_reg_info ()) 1513 if (flag_ira_loop_pressure && resize_reg_info ())
1510 { 1514 {
1511 for (i = 0; VEC_iterate (invariant_p, invariants, i, inv); i++) 1515 FOR_EACH_VEC_ELT (invariant_p, invariants, i, inv)
1512 if (inv->reg != NULL_RTX) 1516 if (inv->reg != NULL_RTX)
1513 { 1517 {
1514 if (inv->orig_regno >= 0) 1518 if (inv->orig_regno >= 0)
1515 setup_reg_classes (REGNO (inv->reg), 1519 setup_reg_classes (REGNO (inv->reg),
1516 reg_preferred_class (inv->orig_regno), 1520 reg_preferred_class (inv->orig_regno),
1555 free (def); 1559 free (def);
1556 invariant_table[i] = NULL; 1560 invariant_table[i] = NULL;
1557 } 1561 }
1558 } 1562 }
1559 1563
1560 for (i = 0; VEC_iterate (invariant_p, invariants, i, inv); i++) 1564 FOR_EACH_VEC_ELT (invariant_p, invariants, i, inv)
1561 { 1565 {
1562 BITMAP_FREE (inv->depends_on); 1566 BITMAP_FREE (inv->depends_on);
1563 free (inv); 1567 free (inv);
1564 } 1568 }
1565 VEC_free (invariant_p, heap, invariants); 1569 VEC_free (invariant_p, heap, invariants);
1571 move_single_loop_invariants (struct loop *loop) 1575 move_single_loop_invariants (struct loop *loop)
1572 { 1576 {
1573 init_inv_motion_data (); 1577 init_inv_motion_data ();
1574 1578
1575 find_invariants (loop); 1579 find_invariants (loop);
1576 find_invariants_to_move (optimize_loop_for_speed_p (loop)); 1580 find_invariants_to_move (optimize_loop_for_speed_p (loop),
1581 LOOP_DATA (loop)->has_call);
1577 move_invariants (loop); 1582 move_invariants (loop);
1578 1583
1579 free_inv_motion_data (); 1584 free_inv_motion_data ();
1580 } 1585 }
1581 1586
1664 1669
1665 for (loop = curr_loop; 1670 for (loop = curr_loop;
1666 loop != current_loops->tree_root; 1671 loop != current_loops->tree_root;
1667 loop = loop_outer (loop)) 1672 loop = loop_outer (loop))
1668 bitmap_set_bit (&LOOP_DATA (loop)->regs_live, regno); 1673 bitmap_set_bit (&LOOP_DATA (loop)->regs_live, regno);
1669 if (bitmap_bit_p (&curr_regs_live, regno)) 1674 if (!bitmap_set_bit (&curr_regs_live, regno))
1670 return; 1675 return;
1671 bitmap_set_bit (&curr_regs_live, regno);
1672 change_pressure (regno, true); 1676 change_pressure (regno, true);
1673 } 1677 }
1674 1678
1675 /* Mark REGNO death. */ 1679 /* Mark REGNO death. */
1676 static void 1680 static void
1677 mark_regno_death (int regno) 1681 mark_regno_death (int regno)
1678 { 1682 {
1679 if (! bitmap_bit_p (&curr_regs_live, regno)) 1683 if (! bitmap_clear_bit (&curr_regs_live, regno))
1680 return; 1684 return;
1681 bitmap_clear_bit (&curr_regs_live, regno);
1682 change_pressure (regno, false); 1685 change_pressure (regno, false);
1683 } 1686 }
1684 1687
1685 /* Mark setting register REG. */ 1688 /* Mark setting register REG. */
1686 static void 1689 static void