Mercurial > hg > CbC > CbC_gcc
comparison gcc/loop-invariant.c @ 63:b7f97abdc517 gcc-4.6-20100522
update gcc from gcc-4.5.0 to gcc-4.6
author | ryoma <e075725@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 24 May 2010 12:47:05 +0900 |
parents | 77e2b8dfacca |
children | f6334be47118 |
comparison
equal
deleted
inserted
replaced
56:3c8a44c06a95 | 63:b7f97abdc517 |
---|---|
1 /* RTL-level loop invariant motion. | 1 /* RTL-level loop invariant motion. |
2 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 | 2 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 |
3 Free Software Foundation, Inc. | 3 Free Software Foundation, Inc. |
4 | 4 |
5 This file is part of GCC. | 5 This file is part of GCC. |
6 | 6 |
7 GCC is free software; you can redistribute it and/or modify it | 7 GCC is free software; you can redistribute it and/or modify it |
1365 += regs_needed[ira_reg_class_cover[i]]; | 1365 += regs_needed[ira_reg_class_cover[i]]; |
1366 } | 1366 } |
1367 } | 1367 } |
1368 } | 1368 } |
1369 | 1369 |
1370 /* Replace the uses, reached by the definition of invariant INV, by REG. | |
1371 | |
1372 IN_GROUP is nonzero if this is part of a group of changes that must be | |
1373 performed as a group. In that case, the changes will be stored. The | |
1374 function `apply_change_group' will validate and apply the changes. */ | |
1375 | |
1376 static int | |
1377 replace_uses (struct invariant *inv, rtx reg, bool in_group) | |
1378 { | |
1379 /* Replace the uses we know to be dominated. It saves work for copy | |
1380 propagation, and also it is necessary so that dependent invariants | |
1381 are computed right. */ | |
1382 if (inv->def) | |
1383 { | |
1384 struct use *use; | |
1385 for (use = inv->def->uses; use; use = use->next) | |
1386 validate_change (use->insn, use->pos, reg, true); | |
1387 | |
1388 /* If we aren't part of a larger group, apply the changes now. */ | |
1389 if (!in_group) | |
1390 return apply_change_group (); | |
1391 } | |
1392 | |
1393 return 1; | |
1394 } | |
1395 | |
1370 /* Move invariant INVNO out of the LOOP. Returns true if this succeeds, false | 1396 /* Move invariant INVNO out of the LOOP. Returns true if this succeeds, false |
1371 otherwise. */ | 1397 otherwise. */ |
1372 | 1398 |
1373 static bool | 1399 static bool |
1374 move_invariant_reg (struct loop *loop, unsigned invno) | 1400 move_invariant_reg (struct loop *loop, unsigned invno) |
1376 struct invariant *inv = VEC_index (invariant_p, invariants, invno); | 1402 struct invariant *inv = VEC_index (invariant_p, invariants, invno); |
1377 struct invariant *repr = VEC_index (invariant_p, invariants, inv->eqto); | 1403 struct invariant *repr = VEC_index (invariant_p, invariants, inv->eqto); |
1378 unsigned i; | 1404 unsigned i; |
1379 basic_block preheader = loop_preheader_edge (loop)->src; | 1405 basic_block preheader = loop_preheader_edge (loop)->src; |
1380 rtx reg, set, dest, note; | 1406 rtx reg, set, dest, note; |
1381 struct use *use; | |
1382 bitmap_iterator bi; | 1407 bitmap_iterator bi; |
1383 int regno; | 1408 int regno = -1; |
1384 | 1409 |
1385 if (inv->reg) | 1410 if (inv->reg) |
1386 return true; | 1411 return true; |
1387 if (!repr->move) | 1412 if (!repr->move) |
1388 return false; | 1413 return false; |
1389 regno = -1; | 1414 |
1390 /* If this is a representative of the class of equivalent invariants, | 1415 /* If this is a representative of the class of equivalent invariants, |
1391 really move the invariant. Otherwise just replace its use with | 1416 really move the invariant. Otherwise just replace its use with |
1392 the register used for the representative. */ | 1417 the register used for the representative. */ |
1393 if (inv == repr) | 1418 if (inv == repr) |
1394 { | 1419 { |
1400 goto fail; | 1425 goto fail; |
1401 } | 1426 } |
1402 } | 1427 } |
1403 | 1428 |
1404 /* Move the set out of the loop. If the set is always executed (we could | 1429 /* Move the set out of the loop. If the set is always executed (we could |
1405 omit this condition if we know that the register is unused outside of the | 1430 omit this condition if we know that the register is unused outside of |
1406 loop, but it does not seem worth finding out) and it has no uses that | 1431 the loop, but it does not seem worth finding out) and it has no uses |
1407 would not be dominated by it, we may just move it (TODO). Otherwise we | 1432 that would not be dominated by it, we may just move it (TODO). |
1408 need to create a temporary register. */ | 1433 Otherwise we need to create a temporary register. */ |
1409 set = single_set (inv->insn); | 1434 set = single_set (inv->insn); |
1410 reg = dest = SET_DEST (set); | 1435 reg = dest = SET_DEST (set); |
1411 if (GET_CODE (reg) == SUBREG) | 1436 if (GET_CODE (reg) == SUBREG) |
1412 reg = SUBREG_REG (reg); | 1437 reg = SUBREG_REG (reg); |
1413 if (REG_P (reg)) | 1438 if (REG_P (reg)) |
1414 regno = REGNO (reg); | 1439 regno = REGNO (reg); |
1415 | 1440 |
1416 reg = gen_reg_rtx_and_attrs (dest); | 1441 reg = gen_reg_rtx_and_attrs (dest); |
1417 | 1442 |
1418 /* Try replacing the destination by a new pseudoregister. */ | 1443 /* Try replacing the destination by a new pseudoregister. */ |
1419 if (!validate_change (inv->insn, &SET_DEST (set), reg, false)) | 1444 validate_change (inv->insn, &SET_DEST (set), reg, true); |
1445 | |
1446 /* As well as all the dominated uses. */ | |
1447 replace_uses (inv, reg, true); | |
1448 | |
1449 /* And validate all the changes. */ | |
1450 if (!apply_change_group ()) | |
1420 goto fail; | 1451 goto fail; |
1421 df_insn_rescan (inv->insn); | |
1422 | 1452 |
1423 emit_insn_after (gen_move_insn (dest, reg), inv->insn); | 1453 emit_insn_after (gen_move_insn (dest, reg), inv->insn); |
1424 reorder_insns (inv->insn, inv->insn, BB_END (preheader)); | 1454 reorder_insns (inv->insn, inv->insn, BB_END (preheader)); |
1425 | 1455 |
1426 /* If there is a REG_EQUAL note on the insn we just moved, and | 1456 /* If there is a REG_EQUAL note on the insn we just moved, and the |
1427 insn is in a basic block that is not always executed, the note | 1457 insn is in a basic block that is not always executed or the note |
1428 may no longer be valid after we move the insn. | 1458 contains something for which we don't know the invariant status, |
1429 Note that uses in REG_EQUAL notes are taken into account in | 1459 the note may no longer be valid after we move the insn. Note that |
1430 the computation of invariants. Hence it is safe to retain the | 1460 uses in REG_EQUAL notes are taken into account in the computation |
1431 note even if the note contains register references. */ | 1461 of invariants, so it is safe to retain the note even if it contains |
1432 if (! inv->always_executed | 1462 register references for which we know the invariant status. */ |
1433 && (note = find_reg_note (inv->insn, REG_EQUAL, NULL_RTX))) | 1463 if ((note = find_reg_note (inv->insn, REG_EQUAL, NULL_RTX)) |
1464 && (!inv->always_executed | |
1465 || !check_maybe_invariant (XEXP (note, 0)))) | |
1434 remove_note (inv->insn, note); | 1466 remove_note (inv->insn, note); |
1435 } | 1467 } |
1436 else | 1468 else |
1437 { | 1469 { |
1438 if (!move_invariant_reg (loop, repr->invno)) | 1470 if (!move_invariant_reg (loop, repr->invno)) |
1439 goto fail; | 1471 goto fail; |
1440 reg = repr->reg; | 1472 reg = repr->reg; |
1441 regno = repr->orig_regno; | 1473 regno = repr->orig_regno; |
1474 if (!replace_uses (inv, reg, false)) | |
1475 goto fail; | |
1442 set = single_set (inv->insn); | 1476 set = single_set (inv->insn); |
1443 emit_insn_after (gen_move_insn (SET_DEST (set), reg), inv->insn); | 1477 emit_insn_after (gen_move_insn (SET_DEST (set), reg), inv->insn); |
1444 delete_insn (inv->insn); | 1478 delete_insn (inv->insn); |
1445 } | 1479 } |
1446 | 1480 |
1447 | |
1448 inv->reg = reg; | 1481 inv->reg = reg; |
1449 inv->orig_regno = regno; | 1482 inv->orig_regno = regno; |
1450 | |
1451 /* Replace the uses we know to be dominated. It saves work for copy | |
1452 propagation, and also it is necessary so that dependent invariants | |
1453 are computed right. */ | |
1454 if (inv->def) | |
1455 { | |
1456 for (use = inv->def->uses; use; use = use->next) | |
1457 { | |
1458 *use->pos = reg; | |
1459 df_insn_rescan (use->insn); | |
1460 } | |
1461 } | |
1462 | 1483 |
1463 return true; | 1484 return true; |
1464 | 1485 |
1465 fail: | 1486 fail: |
1466 /* If we failed, clear move flag, so that we do not try to move inv | 1487 /* If we failed, clear move flag, so that we do not try to move inv |