Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 641 bool HValue::IsInteger32Constant() { | 641 bool HValue::IsInteger32Constant() { |
| 642 return IsConstant() && HConstant::cast(this)->HasInteger32Value(); | 642 return IsConstant() && HConstant::cast(this)->HasInteger32Value(); |
| 643 } | 643 } |
| 644 | 644 |
| 645 | 645 |
| 646 int32_t HValue::GetInteger32Constant() { | 646 int32_t HValue::GetInteger32Constant() { |
| 647 return HConstant::cast(this)->Integer32Value(); | 647 return HConstant::cast(this)->Integer32Value(); |
| 648 } | 648 } |
| 649 | 649 |
| 650 | 650 |
| 651 bool HValue::EqualsInteger32Constant(int32_t value) { | |
| 652 return IsConstant() | |
| 653 && HConstant::cast(this)->HasInteger32Value() | |
| 654 && HConstant::cast(this)->Integer32Value() == value; | |
|
Sven Panne
2013/04/18 09:46:23
Use a combination of IsInteger32Constant and GetIn
| |
| 655 } | |
| 656 | |
| 657 | |
| 651 void HValue::SetOperandAt(int index, HValue* value) { | 658 void HValue::SetOperandAt(int index, HValue* value) { |
| 652 RegisterUse(index, value); | 659 RegisterUse(index, value); |
| 653 InternalSetOperandAt(index, value); | 660 InternalSetOperandAt(index, value); |
| 654 } | 661 } |
| 655 | 662 |
| 656 | 663 |
| 657 void HValue::DeleteAndReplaceWith(HValue* other) { | 664 void HValue::DeleteAndReplaceWith(HValue* other) { |
| 658 // We replace all uses first, so Delete can assert that there are none. | 665 // We replace all uses first, so Delete can assert that there are none. |
| 659 if (other != NULL) ReplaceAllUsesWith(other); | 666 if (other != NULL) ReplaceAllUsesWith(other); |
| 660 ASSERT(HasNoUses()); | 667 ASSERT(HasNoUses()); |
| (...skipping 725 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1386 object()->PrintNameTo(stream); | 1393 object()->PrintNameTo(stream); |
| 1387 stream->Add(" "); | 1394 stream->Add(" "); |
| 1388 index()->PrintNameTo(stream); | 1395 index()->PrintNameTo(stream); |
| 1389 } | 1396 } |
| 1390 | 1397 |
| 1391 | 1398 |
| 1392 HValue* HBitwise::Canonicalize() { | 1399 HValue* HBitwise::Canonicalize() { |
| 1393 if (!representation().IsInteger32()) return this; | 1400 if (!representation().IsInteger32()) return this; |
| 1394 // If x is an int32, then x & -1 == x, x | 0 == x and x ^ 0 == x. | 1401 // If x is an int32, then x & -1 == x, x | 0 == x and x ^ 0 == x. |
| 1395 int32_t nop_constant = (op() == Token::BIT_AND) ? -1 : 0; | 1402 int32_t nop_constant = (op() == Token::BIT_AND) ? -1 : 0; |
| 1396 if (left()->IsConstant() && | 1403 if (left()->EqualsInteger32Constant(nop_constant) && |
| 1397 HConstant::cast(left())->HasInteger32Value() && | |
| 1398 HConstant::cast(left())->Integer32Value() == nop_constant && | |
| 1399 !right()->CheckFlag(kUint32)) { | 1404 !right()->CheckFlag(kUint32)) { |
| 1400 return right(); | 1405 return right(); |
| 1401 } | 1406 } |
| 1402 if (right()->IsConstant() && | 1407 if (right()->EqualsInteger32Constant(nop_constant) && |
| 1403 HConstant::cast(right())->HasInteger32Value() && | |
| 1404 HConstant::cast(right())->Integer32Value() == nop_constant && | |
| 1405 !left()->CheckFlag(kUint32)) { | 1408 !left()->CheckFlag(kUint32)) { |
| 1406 return left(); | 1409 return left(); |
| 1407 } | 1410 } |
| 1408 return this; | 1411 return this; |
| 1409 } | 1412 } |
| 1410 | 1413 |
| 1411 | 1414 |
| 1412 HValue* HBitNot::Canonicalize() { | 1415 HValue* HBitNot::Canonicalize() { |
| 1413 // Optimize ~~x, a common pattern used for ToInt32(x). | 1416 // Optimize ~~x, a common pattern used for ToInt32(x). |
| 1414 if (value()->IsBitNot()) { | 1417 if (value()->IsBitNot()) { |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 1432 HValue* HSub::Canonicalize() { | 1435 HValue* HSub::Canonicalize() { |
| 1433 if (!representation().IsInteger32()) return this; | 1436 if (!representation().IsInteger32()) return this; |
| 1434 if (CheckUsesForFlag(kTruncatingToInt32)) ClearFlag(kCanOverflow); | 1437 if (CheckUsesForFlag(kTruncatingToInt32)) ClearFlag(kCanOverflow); |
| 1435 return this; | 1438 return this; |
| 1436 } | 1439 } |
| 1437 | 1440 |
| 1438 | 1441 |
| 1439 // TODO(svenpanne) Use this in other Canonicalize() functions. | 1442 // TODO(svenpanne) Use this in other Canonicalize() functions. |
| 1440 static bool IsIdentityOperation(HValue* arg1, HValue* arg2, int32_t identity) { | 1443 static bool IsIdentityOperation(HValue* arg1, HValue* arg2, int32_t identity) { |
| 1441 return arg1->representation().IsSpecialization() && | 1444 return arg1->representation().IsSpecialization() && |
| 1442 arg2->IsInteger32Constant() && | 1445 arg2->EqualsInteger32Constant(identity); |
| 1443 arg2->GetInteger32Constant() == identity; | |
| 1444 } | 1446 } |
| 1445 | 1447 |
| 1446 | 1448 |
| 1447 HValue* HMul::Canonicalize() { | 1449 HValue* HMul::Canonicalize() { |
| 1448 if (IsIdentityOperation(left(), right(), 1)) return left(); | 1450 if (IsIdentityOperation(left(), right(), 1)) return left(); |
| 1449 if (IsIdentityOperation(right(), left(), 1)) return right(); | 1451 if (IsIdentityOperation(right(), left(), 1)) return right(); |
| 1450 return this; | 1452 return this; |
| 1451 } | 1453 } |
| 1452 | 1454 |
| 1453 | 1455 |
| (...skipping 2131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3585 | 3587 |
| 3586 | 3588 |
| 3587 void HCheckFunction::Verify() { | 3589 void HCheckFunction::Verify() { |
| 3588 HInstruction::Verify(); | 3590 HInstruction::Verify(); |
| 3589 ASSERT(HasNoUses()); | 3591 ASSERT(HasNoUses()); |
| 3590 } | 3592 } |
| 3591 | 3593 |
| 3592 #endif | 3594 #endif |
| 3593 | 3595 |
| 3594 } } // namespace v8::internal | 3596 } } // namespace v8::internal |
| OLD | NEW |