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 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 398 return false; | 398 return false; |
| 399 } | 399 } |
| 400 } | 400 } |
| 401 | 401 |
| 402 | 402 |
| 403 bool HValue::TestDominanceUsingProcessedFlag(HValue* dominator, | 403 bool HValue::TestDominanceUsingProcessedFlag(HValue* dominator, |
| 404 HValue* dominated) { | 404 HValue* dominated) { |
| 405 if (dominator->block() != dominated->block()) { | 405 if (dominator->block() != dominated->block()) { |
| 406 return dominator->block()->Dominates(dominated->block()); | 406 return dominator->block()->Dominates(dominated->block()); |
| 407 } else { | 407 } else { |
| 408 // If both arguments are in the same block we check if "dominator" has | 408 // If both arguments are in the same block we check if dominator is a phi |
| 409 // already been processed or if it is a phi: if yes it dominates the other. | 409 // or if dominated has not already been processed: in either case we know |
| 410 return dominator->CheckFlag(kIDefsProcessingDone) || dominator->IsPhi(); | 410 // that dominator precedes dominated. |
| 411 return dominator->IsPhi() || !dominated->CheckFlag(kIDefsProcessingDone); | |
| 411 } | 412 } |
| 412 } | 413 } |
| 413 | 414 |
| 414 | 415 |
| 415 bool HValue::IsDefinedAfter(HBasicBlock* other) const { | 416 bool HValue::IsDefinedAfter(HBasicBlock* other) const { |
| 416 return block()->block_id() > other->block_id(); | 417 return block()->block_id() > other->block_id(); |
| 417 } | 418 } |
| 418 | 419 |
| 419 | 420 |
| 420 HUseListNode* HUseListNode::tail() { | 421 HUseListNode* HUseListNode::tail() { |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 517 switch (opcode()) { | 518 switch (opcode()) { |
| 518 #define MAKE_CASE(type) case k##type: return #type; | 519 #define MAKE_CASE(type) case k##type: return #type; |
| 519 HYDROGEN_CONCRETE_INSTRUCTION_LIST(MAKE_CASE) | 520 HYDROGEN_CONCRETE_INSTRUCTION_LIST(MAKE_CASE) |
| 520 #undef MAKE_CASE | 521 #undef MAKE_CASE |
| 521 case kPhi: return "Phi"; | 522 case kPhi: return "Phi"; |
| 522 default: return ""; | 523 default: return ""; |
| 523 } | 524 } |
| 524 } | 525 } |
| 525 | 526 |
| 526 | 527 |
| 528 bool HValue::IsInteger32Constant() { | |
| 529 return IsConstant() && HConstant::cast(this)->HasInteger32Value(); | |
| 530 } | |
| 531 | |
| 532 | |
| 533 int32_t HValue::GetInteger32Constant() { | |
| 534 ASSERT(IsInteger32Constant()); | |
| 535 return HConstant::cast(this)->Integer32Value(); | |
| 536 } | |
| 537 | |
| 538 | |
| 527 void HValue::SetOperandAt(int index, HValue* value) { | 539 void HValue::SetOperandAt(int index, HValue* value) { |
| 528 RegisterUse(index, value); | 540 RegisterUse(index, value); |
| 529 InternalSetOperandAt(index, value); | 541 InternalSetOperandAt(index, value); |
| 530 } | 542 } |
| 531 | 543 |
| 532 | 544 |
| 533 void HValue::DeleteAndReplaceWith(HValue* other) { | 545 void HValue::DeleteAndReplaceWith(HValue* other) { |
| 534 // We replace all uses first, so Delete can assert that there are none. | 546 // We replace all uses first, so Delete can assert that there are none. |
| 535 if (other != NULL) ReplaceAllUsesWith(other); | 547 if (other != NULL) ReplaceAllUsesWith(other); |
| 536 ASSERT(HasNoUses()); | 548 ASSERT(HasNoUses()); |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 683 PrintChangesTo(stream); | 695 PrintChangesTo(stream); |
| 684 PrintTypeTo(stream); | 696 PrintTypeTo(stream); |
| 685 } | 697 } |
| 686 | 698 |
| 687 | 699 |
| 688 void HInstruction::PrintMnemonicTo(StringStream* stream) { | 700 void HInstruction::PrintMnemonicTo(StringStream* stream) { |
| 689 stream->Add("%s ", Mnemonic()); | 701 stream->Add("%s ", Mnemonic()); |
| 690 } | 702 } |
| 691 | 703 |
| 692 | 704 |
| 705 HValue* HValue::AddNumericConstraint(HInstruction* insertion_point, | |
| 706 HValue* related_value, | |
| 707 NumericRelation relation) { | |
| 708 return HNumericConstraint::New( | |
| 709 insertion_point, this, related_value, relation); | |
| 710 } | |
| 711 | |
| 712 | |
| 693 void HInstruction::Unlink() { | 713 void HInstruction::Unlink() { |
| 694 ASSERT(IsLinked()); | 714 ASSERT(IsLinked()); |
| 695 ASSERT(!IsControlInstruction()); // Must never move control instructions. | 715 ASSERT(!IsControlInstruction()); // Must never move control instructions. |
| 696 ASSERT(!IsBlockEntry()); // Doesn't make sense to delete these. | 716 ASSERT(!IsBlockEntry()); // Doesn't make sense to delete these. |
| 697 ASSERT(previous_ != NULL); | 717 ASSERT(previous_ != NULL); |
| 698 previous_->next_ = next_; | 718 previous_->next_ = next_; |
| 699 if (next_ == NULL) { | 719 if (next_ == NULL) { |
| 700 ASSERT(block()->last() == this); | 720 ASSERT(block()->last() == this); |
| 701 block()->set_last(previous_); | 721 block()->set_last(previous_); |
| 702 } else { | 722 } else { |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 787 } | 807 } |
| 788 | 808 |
| 789 // Verify that instructions that can be eliminated by GVN have overridden | 809 // Verify that instructions that can be eliminated by GVN have overridden |
| 790 // HValue::DataEquals. The default implementation is UNREACHABLE. We | 810 // HValue::DataEquals. The default implementation is UNREACHABLE. We |
| 791 // don't actually care whether DataEquals returns true or false here. | 811 // don't actually care whether DataEquals returns true or false here. |
| 792 if (CheckFlag(kUseGVN)) DataEquals(this); | 812 if (CheckFlag(kUseGVN)) DataEquals(this); |
| 793 } | 813 } |
| 794 #endif | 814 #endif |
| 795 | 815 |
| 796 | 816 |
| 817 HNumericConstraint* HNumericConstraint::New(HInstruction* insertion_point, | |
| 818 HValue* constrained_value, | |
| 819 HValue* related_value, | |
| 820 NumericRelation relation) { | |
| 821 HNumericConstraint* result = | |
| 822 new(insertion_point->block()->zone()) HNumericConstraint( | |
| 823 constrained_value, related_value, relation); | |
| 824 result->InsertAfter(insertion_point); | |
| 825 return result; | |
| 826 } | |
| 827 | |
| 828 | |
| 829 void HNumericConstraint::PrintDataTo(StringStream* stream) { | |
| 830 stream->Add("("); | |
| 831 constrained_value()->PrintNameTo(stream); | |
| 832 stream->Add(" %s ", relation().Mnemonic()); | |
| 833 related_value()->PrintNameTo(stream); | |
| 834 stream->Add(")"); | |
| 835 } | |
| 836 | |
| 837 | |
| 797 void HDummyUse::PrintDataTo(StringStream* stream) { | 838 void HDummyUse::PrintDataTo(StringStream* stream) { |
| 798 value()->PrintNameTo(stream); | 839 value()->PrintNameTo(stream); |
| 799 } | 840 } |
| 800 | 841 |
| 801 | 842 |
| 802 void HUnaryCall::PrintDataTo(StringStream* stream) { | 843 void HUnaryCall::PrintDataTo(StringStream* stream) { |
| 803 value()->PrintNameTo(stream); | 844 value()->PrintNameTo(stream); |
| 804 stream->Add(" "); | 845 stream->Add(" "); |
| 805 stream->Add("#%d", argument_count()); | 846 stream->Add("#%d", argument_count()); |
| 806 } | 847 } |
| 807 | 848 |
| 808 | 849 |
| 809 void HBinaryCall::PrintDataTo(StringStream* stream) { | 850 void HBinaryCall::PrintDataTo(StringStream* stream) { |
| 810 first()->PrintNameTo(stream); | 851 first()->PrintNameTo(stream); |
| 811 stream->Add(" "); | 852 stream->Add(" "); |
| 812 second()->PrintNameTo(stream); | 853 second()->PrintNameTo(stream); |
| 813 stream->Add(" "); | 854 stream->Add(" "); |
| 814 stream->Add("#%d", argument_count()); | 855 stream->Add("#%d", argument_count()); |
| 815 } | 856 } |
| 816 | 857 |
| 817 | 858 |
| 859 void HBoundsCheck::AddInformativeDefinitions() { | |
|
Jakob Kummerow
2013/02/12 15:10:42
As discussed, having this logic in this pass is a
Massi
2013/02/13 11:56:42
Done.
| |
| 860 if (index()->IsRelationTrue( | |
| 861 NumericRelation::Ge(), block()->graph()->GetConstant0()) | |
|
Jakob Kummerow
2013/02/12 15:10:42
indentation:
void HBoundsCheck::AddInformativeDef
Massi
2013/02/13 11:56:42
Done.
| |
| 862 && index()->IsRelationTrue(NumericRelation::Lt(), length())) { | |
| 863 set_skip_check(true); | |
|
Jakob Kummerow
2013/02/12 15:10:42
As discussed, it should be possible to just remove
Massi
2013/02/13 11:56:42
Done.
| |
| 864 } | |
| 865 } | |
| 866 | |
| 867 | |
| 868 bool HBoundsCheck::CheckRelation(NumericRelation relation, | |
| 869 HValue* related_value) { | |
| 870 if (related_value == length()) { | |
| 871 return NumericRelation::Lt().Implies(relation); | |
| 872 } else if (related_value == block()->graph()->GetConstant0()) { | |
| 873 return NumericRelation::Ge().Implies(relation); | |
| 874 } else { | |
| 875 return false; | |
| 876 } | |
| 877 } | |
| 878 | |
| 879 | |
| 818 void HBoundsCheck::PrintDataTo(StringStream* stream) { | 880 void HBoundsCheck::PrintDataTo(StringStream* stream) { |
| 819 index()->PrintNameTo(stream); | 881 index()->PrintNameTo(stream); |
| 820 stream->Add(" "); | 882 stream->Add(" "); |
| 821 length()->PrintNameTo(stream); | 883 length()->PrintNameTo(stream); |
| 884 if (skip_check()) { | |
| 885 stream->Add(" [DISABLED]"); | |
| 886 } | |
| 822 } | 887 } |
| 823 | 888 |
| 824 | 889 |
| 825 void HBoundsCheck::InferRepresentation(HInferRepresentation* h_infer) { | 890 void HBoundsCheck::InferRepresentation(HInferRepresentation* h_infer) { |
| 826 ASSERT(CheckFlag(kFlexibleRepresentation)); | 891 ASSERT(CheckFlag(kFlexibleRepresentation)); |
| 827 Representation r; | 892 Representation r; |
| 828 if (key_mode_ == DONT_ALLOW_SMI_KEY || | 893 if (key_mode_ == DONT_ALLOW_SMI_KEY || |
| 829 !length()->representation().IsTagged()) { | 894 !length()->representation().IsTagged()) { |
| 830 r = Representation::Integer32(); | 895 r = Representation::Integer32(); |
| 831 } else if (index()->representation().IsTagged() || | 896 } else if (index()->representation().IsTagged() || |
| (...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1468 if (!right()->range()->CanBeZero()) { | 1533 if (!right()->range()->CanBeZero()) { |
| 1469 ClearFlag(HValue::kCanBeDivByZero); | 1534 ClearFlag(HValue::kCanBeDivByZero); |
| 1470 } | 1535 } |
| 1471 return result; | 1536 return result; |
| 1472 } else { | 1537 } else { |
| 1473 return HValue::InferRange(zone); | 1538 return HValue::InferRange(zone); |
| 1474 } | 1539 } |
| 1475 } | 1540 } |
| 1476 | 1541 |
| 1477 | 1542 |
| 1543 void HPhi::AddInformativeDefinitions() { | |
| 1544 HValue* induction_base = NULL; | |
| 1545 NumericRelation relation = NumericRelation::None(); | |
| 1546 if (OperandCount() == 2) { | |
| 1547 if (OperandAt(0)->IsRelationTrue(NumericRelation::Ge(), this)) { | |
| 1548 induction_base = OperandAt(1); | |
| 1549 relation = NumericRelation::Ge(); | |
| 1550 } else if (OperandAt(0)->IsRelationTrue(NumericRelation::Le(), this)) { | |
| 1551 induction_base = OperandAt(1); | |
| 1552 relation = NumericRelation::Ge(); | |
| 1553 } else if (OperandAt(1)->IsRelationTrue(NumericRelation::Ge(), this)) { | |
| 1554 induction_base = OperandAt(0); | |
| 1555 relation = NumericRelation::Ge(); | |
| 1556 } else if (OperandAt(1)->IsRelationTrue(NumericRelation::Le(), this)) { | |
| 1557 induction_base = OperandAt(0); | |
| 1558 relation = NumericRelation::Ge(); | |
| 1559 } | |
| 1560 } | |
| 1561 | |
| 1562 if (induction_base == NULL) return; | |
| 1563 | |
| 1564 AddNumericConstraint(block()->first(), induction_base, relation); | |
| 1565 } | |
| 1566 | |
| 1567 | |
| 1478 Range* HMathMinMax::InferRange(Zone* zone) { | 1568 Range* HMathMinMax::InferRange(Zone* zone) { |
| 1479 if (representation().IsInteger32()) { | 1569 if (representation().IsInteger32()) { |
| 1480 Range* a = left()->range(); | 1570 Range* a = left()->range(); |
| 1481 Range* b = right()->range(); | 1571 Range* b = right()->range(); |
| 1482 Range* res = a->Copy(zone); | 1572 Range* res = a->Copy(zone); |
| 1483 if (operation_ == kMathMax) { | 1573 if (operation_ == kMathMax) { |
| 1484 res->CombinedMax(b); | 1574 res->CombinedMax(b); |
| 1485 } else { | 1575 } else { |
| 1486 ASSERT(operation_ == kMathMin); | 1576 ASSERT(operation_ == kMathMin); |
| 1487 res->CombinedMin(b); | 1577 res->CombinedMin(b); |
| (...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1881 result->Sar(c->Integer32Value()); | 1971 result->Sar(c->Integer32Value()); |
| 1882 result->set_can_be_minus_zero(false); | 1972 result->set_can_be_minus_zero(false); |
| 1883 return result; | 1973 return result; |
| 1884 } | 1974 } |
| 1885 } | 1975 } |
| 1886 } | 1976 } |
| 1887 return HValue::InferRange(zone); | 1977 return HValue::InferRange(zone); |
| 1888 } | 1978 } |
| 1889 | 1979 |
| 1890 | 1980 |
| 1981 bool HShr::CheckRelation(NumericRelation relation, HValue* other) { | |
| 1982 if (right()->IsInteger32Constant()) { | |
| 1983 HValue* base = left(); | |
| 1984 int32_t bits = right()->GetInteger32Constant(); | |
| 1985 if (relation.IsExtendable(-bits) && | |
| 1986 base->IsRelationTrue(NumericRelation::Ge(), | |
| 1987 block()->graph()->GetConstant0())) { | |
| 1988 return base->IsRelationTrue(relation, other); | |
| 1989 } else { | |
| 1990 return false; | |
| 1991 } | |
| 1992 } else { | |
| 1993 return false; | |
| 1994 } | |
| 1995 } | |
| 1996 | |
| 1997 | |
| 1891 Range* HShl::InferRange(Zone* zone) { | 1998 Range* HShl::InferRange(Zone* zone) { |
| 1892 if (right()->IsConstant()) { | 1999 if (right()->IsConstant()) { |
| 1893 HConstant* c = HConstant::cast(right()); | 2000 HConstant* c = HConstant::cast(right()); |
| 1894 if (c->HasInteger32Value()) { | 2001 if (c->HasInteger32Value()) { |
| 1895 Range* result = (left()->range() != NULL) | 2002 Range* result = (left()->range() != NULL) |
| 1896 ? left()->range()->Copy(zone) | 2003 ? left()->range()->Copy(zone) |
| 1897 : new(zone) Range(); | 2004 : new(zone) Range(); |
| 1898 result->Shl(c->Integer32Value()); | 2005 result->Shl(c->Integer32Value()); |
| 1899 result->set_can_be_minus_zero(false); | 2006 result->set_can_be_minus_zero(false); |
| 1900 return result; | 2007 return result; |
| 1901 } | 2008 } |
| 1902 } | 2009 } |
| 1903 return HValue::InferRange(zone); | 2010 return HValue::InferRange(zone); |
| 1904 } | 2011 } |
| 1905 | 2012 |
| 1906 | 2013 |
| 2014 bool HShl::CheckRelation(NumericRelation relation, HValue* other) { | |
| 2015 if (right()->IsInteger32Constant()) { | |
| 2016 HValue* base = left(); | |
| 2017 int32_t bits = right()->GetInteger32Constant(); | |
| 2018 if (relation.IsExtendable(bits) && | |
| 2019 base->IsRelationTrue(NumericRelation::Ge(), | |
| 2020 block()->graph()->GetConstant0())) { | |
| 2021 return base->IsRelationTrue(relation, other); | |
| 2022 } else { | |
| 2023 return false; | |
| 2024 } | |
| 2025 } else { | |
| 2026 return false; | |
| 2027 } | |
| 2028 } | |
| 2029 | |
| 2030 | |
| 1907 Range* HLoadKeyed::InferRange(Zone* zone) { | 2031 Range* HLoadKeyed::InferRange(Zone* zone) { |
| 1908 switch (elements_kind()) { | 2032 switch (elements_kind()) { |
| 1909 case EXTERNAL_PIXEL_ELEMENTS: | 2033 case EXTERNAL_PIXEL_ELEMENTS: |
| 1910 return new(zone) Range(0, 255); | 2034 return new(zone) Range(0, 255); |
| 1911 case EXTERNAL_BYTE_ELEMENTS: | 2035 case EXTERNAL_BYTE_ELEMENTS: |
| 1912 return new(zone) Range(-128, 127); | 2036 return new(zone) Range(-128, 127); |
| 1913 case EXTERNAL_UNSIGNED_BYTE_ELEMENTS: | 2037 case EXTERNAL_UNSIGNED_BYTE_ELEMENTS: |
| 1914 return new(zone) Range(0, 255); | 2038 return new(zone) Range(0, 255); |
| 1915 case EXTERNAL_SHORT_ELEMENTS: | 2039 case EXTERNAL_SHORT_ELEMENTS: |
| 1916 return new(zone) Range(-32768, 32767); | 2040 return new(zone) Range(-32768, 32767); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 1929 } | 2053 } |
| 1930 | 2054 |
| 1931 | 2055 |
| 1932 void HStringCompareAndBranch::PrintDataTo(StringStream* stream) { | 2056 void HStringCompareAndBranch::PrintDataTo(StringStream* stream) { |
| 1933 stream->Add(Token::Name(token())); | 2057 stream->Add(Token::Name(token())); |
| 1934 stream->Add(" "); | 2058 stream->Add(" "); |
| 1935 HControlInstruction::PrintDataTo(stream); | 2059 HControlInstruction::PrintDataTo(stream); |
| 1936 } | 2060 } |
| 1937 | 2061 |
| 1938 | 2062 |
| 2063 void HCompareIDAndBranch::AddInformativeDefinitions() { | |
| 2064 NumericRelation r = NumericRelation::FromToken(token()); | |
| 2065 if (r == NumericRelation::None()) return; | |
| 2066 | |
| 2067 left()->AddNumericConstraint(SuccessorAt(0)->first(), right(), r.Reversed()); | |
| 2068 left()->AddNumericConstraint(SuccessorAt(1)->first(), right(), r); | |
| 2069 } | |
| 2070 | |
| 2071 | |
| 1939 void HCompareIDAndBranch::PrintDataTo(StringStream* stream) { | 2072 void HCompareIDAndBranch::PrintDataTo(StringStream* stream) { |
| 1940 stream->Add(Token::Name(token())); | 2073 stream->Add(Token::Name(token())); |
| 1941 stream->Add(" "); | 2074 stream->Add(" "); |
| 1942 left()->PrintNameTo(stream); | 2075 left()->PrintNameTo(stream); |
| 1943 stream->Add(" "); | 2076 stream->Add(" "); |
| 1944 right()->PrintNameTo(stream); | 2077 right()->PrintNameTo(stream); |
| 1945 HControlInstruction::PrintDataTo(stream); | 2078 HControlInstruction::PrintDataTo(stream); |
| 1946 } | 2079 } |
| 1947 | 2080 |
| 1948 | 2081 |
| (...skipping 992 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2941 | 3074 |
| 2942 | 3075 |
| 2943 void HCheckFunction::Verify() { | 3076 void HCheckFunction::Verify() { |
| 2944 HInstruction::Verify(); | 3077 HInstruction::Verify(); |
| 2945 ASSERT(HasNoUses()); | 3078 ASSERT(HasNoUses()); |
| 2946 } | 3079 } |
| 2947 | 3080 |
| 2948 #endif | 3081 #endif |
| 2949 | 3082 |
| 2950 } } // namespace v8::internal | 3083 } } // namespace v8::internal |
| OLD | NEW |