Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(34)

Side by Side Diff: src/hydrogen-instructions.cc

Issue 12226112: Infrastructure classes for evaluating numeric relations between values. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Added basic support for numeric relations with the result of an arithmetical operation. Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 506 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 switch (opcode()) { 517 switch (opcode()) {
518 #define MAKE_CASE(type) case k##type: return #type; 518 #define MAKE_CASE(type) case k##type: return #type;
519 HYDROGEN_CONCRETE_INSTRUCTION_LIST(MAKE_CASE) 519 HYDROGEN_CONCRETE_INSTRUCTION_LIST(MAKE_CASE)
520 #undef MAKE_CASE 520 #undef MAKE_CASE
521 case kPhi: return "Phi"; 521 case kPhi: return "Phi";
522 default: return ""; 522 default: return "";
523 } 523 }
524 } 524 }
525 525
526 526
527 bool HValue::IsInteger32Constant() {
528 return IsConstant() && HConstant::cast(this)->HasInteger32Value();
529 }
530
531
532 int32_t HValue::GetInteger32Constant() {
533 ASSERT(IsInteger32Constant());
Jakob Kummerow 2013/02/12 15:10:42 we don't need this ASSERT, as the cast and Integer
Massi 2013/02/13 11:56:42 Done.
534 return HConstant::cast(this)->Integer32Value();
535 }
536
537
527 void HValue::SetOperandAt(int index, HValue* value) { 538 void HValue::SetOperandAt(int index, HValue* value) {
528 RegisterUse(index, value); 539 RegisterUse(index, value);
529 InternalSetOperandAt(index, value); 540 InternalSetOperandAt(index, value);
530 } 541 }
531 542
532 543
533 void HValue::DeleteAndReplaceWith(HValue* other) { 544 void HValue::DeleteAndReplaceWith(HValue* other) {
534 // We replace all uses first, so Delete can assert that there are none. 545 // We replace all uses first, so Delete can assert that there are none.
535 if (other != NULL) ReplaceAllUsesWith(other); 546 if (other != NULL) ReplaceAllUsesWith(other);
536 ASSERT(HasNoUses()); 547 ASSERT(HasNoUses());
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 PrintChangesTo(stream); 694 PrintChangesTo(stream);
684 PrintTypeTo(stream); 695 PrintTypeTo(stream);
685 } 696 }
686 697
687 698
688 void HInstruction::PrintMnemonicTo(StringStream* stream) { 699 void HInstruction::PrintMnemonicTo(StringStream* stream) {
689 stream->Add("%s ", Mnemonic()); 700 stream->Add("%s ", Mnemonic());
690 } 701 }
691 702
692 703
704 HValue* HValue::AddNumericConstraint(HInstruction* insertion_point,
705 HValue* related_value,
706 NumericRelation relation) {
707 return HNumericConstraint::New(
708 insertion_point, this, related_value, relation);
709 }
710
711
693 void HInstruction::Unlink() { 712 void HInstruction::Unlink() {
694 ASSERT(IsLinked()); 713 ASSERT(IsLinked());
695 ASSERT(!IsControlInstruction()); // Must never move control instructions. 714 ASSERT(!IsControlInstruction()); // Must never move control instructions.
696 ASSERT(!IsBlockEntry()); // Doesn't make sense to delete these. 715 ASSERT(!IsBlockEntry()); // Doesn't make sense to delete these.
697 ASSERT(previous_ != NULL); 716 ASSERT(previous_ != NULL);
698 previous_->next_ = next_; 717 previous_->next_ = next_;
699 if (next_ == NULL) { 718 if (next_ == NULL) {
700 ASSERT(block()->last() == this); 719 ASSERT(block()->last() == this);
701 block()->set_last(previous_); 720 block()->set_last(previous_);
702 } else { 721 } else {
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
787 } 806 }
788 807
789 // Verify that instructions that can be eliminated by GVN have overridden 808 // Verify that instructions that can be eliminated by GVN have overridden
790 // HValue::DataEquals. The default implementation is UNREACHABLE. We 809 // HValue::DataEquals. The default implementation is UNREACHABLE. We
791 // don't actually care whether DataEquals returns true or false here. 810 // don't actually care whether DataEquals returns true or false here.
792 if (CheckFlag(kUseGVN)) DataEquals(this); 811 if (CheckFlag(kUseGVN)) DataEquals(this);
793 } 812 }
794 #endif 813 #endif
795 814
796 815
816 HNumericConstraint* HNumericConstraint::New(HInstruction* insertion_point,
817 HValue* constrained_value,
818 HValue* related_value,
819 NumericRelation relation) {
820 HNumericConstraint* result =
821 new(insertion_point->block()->zone()) HNumericConstraint(
822 constrained_value, related_value, relation);
823 result->InsertAfter(insertion_point);
824 return result;
825 }
826
827
828 void HNumericConstraint::PrintDataTo(StringStream* stream) {
829 stream->Add("(");
830 constrained_value()->PrintNameTo(stream);
831 stream->Add(" %s ", relation().Mnemonic());
832 related_value()->PrintNameTo(stream);
833 stream->Add(")");
834 }
835
836
797 void HDummyUse::PrintDataTo(StringStream* stream) { 837 void HDummyUse::PrintDataTo(StringStream* stream) {
798 value()->PrintNameTo(stream); 838 value()->PrintNameTo(stream);
799 } 839 }
800 840
801 841
802 void HUnaryCall::PrintDataTo(StringStream* stream) { 842 void HUnaryCall::PrintDataTo(StringStream* stream) {
803 value()->PrintNameTo(stream); 843 value()->PrintNameTo(stream);
804 stream->Add(" "); 844 stream->Add(" ");
805 stream->Add("#%d", argument_count()); 845 stream->Add("#%d", argument_count());
806 } 846 }
807 847
808 848
809 void HBinaryCall::PrintDataTo(StringStream* stream) { 849 void HBinaryCall::PrintDataTo(StringStream* stream) {
810 first()->PrintNameTo(stream); 850 first()->PrintNameTo(stream);
811 stream->Add(" "); 851 stream->Add(" ");
812 second()->PrintNameTo(stream); 852 second()->PrintNameTo(stream);
813 stream->Add(" "); 853 stream->Add(" ");
814 stream->Add("#%d", argument_count()); 854 stream->Add("#%d", argument_count());
815 } 855 }
816 856
817 857
858 bool HBoundsCheck::CheckRelation(NumericRelation relation,
859 HValue* related_value) {
860 if (related_value == length()) {
861 return NumericRelation::Lt().Implies(relation);
862 } else if (related_value == block()->graph()->GetConstant0()) {
863 return NumericRelation::Ge().Implies(relation);
864 } else {
865 return false;
866 }
867 }
868
869
818 void HBoundsCheck::PrintDataTo(StringStream* stream) { 870 void HBoundsCheck::PrintDataTo(StringStream* stream) {
819 index()->PrintNameTo(stream); 871 index()->PrintNameTo(stream);
820 stream->Add(" "); 872 stream->Add(" ");
821 length()->PrintNameTo(stream); 873 length()->PrintNameTo(stream);
822 } 874 }
823 875
824 876
825 void HBoundsCheck::InferRepresentation(HInferRepresentation* h_infer) { 877 void HBoundsCheck::InferRepresentation(HInferRepresentation* h_infer) {
826 ASSERT(CheckFlag(kFlexibleRepresentation)); 878 ASSERT(CheckFlag(kFlexibleRepresentation));
827 Representation r; 879 Representation r;
(...skipping 1053 matching lines...) Expand 10 before | Expand all | Expand 10 after
1881 result->Sar(c->Integer32Value()); 1933 result->Sar(c->Integer32Value());
1882 result->set_can_be_minus_zero(false); 1934 result->set_can_be_minus_zero(false);
1883 return result; 1935 return result;
1884 } 1936 }
1885 } 1937 }
1886 } 1938 }
1887 return HValue::InferRange(zone); 1939 return HValue::InferRange(zone);
1888 } 1940 }
1889 1941
1890 1942
1943 bool HShr::CheckRelation(NumericRelation relation, HValue* other) {
Jakob Kummerow 2013/02/12 15:10:42 Let's skip these too for now.
Massi 2013/02/13 11:56:42 Done.
1944 if (right()->IsInteger32Constant()) {
1945 HValue* base = left();
1946 int32_t bits = right()->GetInteger32Constant();
1947 if (relation.IsExtendable(-bits) &&
1948 base->IsRelationTrue(NumericRelation::Ge(),
1949 block()->graph()->GetConstant0())) {
1950 return base->IsRelationTrue(relation, other);
1951 } else {
1952 return false;
1953 }
1954 } else {
1955 return false;
1956 }
1957 }
1958
1959
1891 Range* HShl::InferRange(Zone* zone) { 1960 Range* HShl::InferRange(Zone* zone) {
1892 if (right()->IsConstant()) { 1961 if (right()->IsConstant()) {
1893 HConstant* c = HConstant::cast(right()); 1962 HConstant* c = HConstant::cast(right());
1894 if (c->HasInteger32Value()) { 1963 if (c->HasInteger32Value()) {
1895 Range* result = (left()->range() != NULL) 1964 Range* result = (left()->range() != NULL)
1896 ? left()->range()->Copy(zone) 1965 ? left()->range()->Copy(zone)
1897 : new(zone) Range(); 1966 : new(zone) Range();
1898 result->Shl(c->Integer32Value()); 1967 result->Shl(c->Integer32Value());
1899 result->set_can_be_minus_zero(false); 1968 result->set_can_be_minus_zero(false);
1900 return result; 1969 return result;
1901 } 1970 }
1902 } 1971 }
1903 return HValue::InferRange(zone); 1972 return HValue::InferRange(zone);
1904 } 1973 }
1905 1974
1906 1975
1976 bool HShl::CheckRelation(NumericRelation relation, HValue* other) {
1977 if (right()->IsInteger32Constant()) {
1978 HValue* base = left();
1979 int32_t bits = right()->GetInteger32Constant();
1980 if (relation.IsExtendable(bits) &&
1981 base->IsRelationTrue(NumericRelation::Ge(),
1982 block()->graph()->GetConstant0())) {
1983 return base->IsRelationTrue(relation, other);
1984 } else {
1985 return false;
1986 }
1987 } else {
1988 return false;
1989 }
1990 }
1991
1992
1907 Range* HLoadKeyed::InferRange(Zone* zone) { 1993 Range* HLoadKeyed::InferRange(Zone* zone) {
1908 switch (elements_kind()) { 1994 switch (elements_kind()) {
1909 case EXTERNAL_PIXEL_ELEMENTS: 1995 case EXTERNAL_PIXEL_ELEMENTS:
1910 return new(zone) Range(0, 255); 1996 return new(zone) Range(0, 255);
1911 case EXTERNAL_BYTE_ELEMENTS: 1997 case EXTERNAL_BYTE_ELEMENTS:
1912 return new(zone) Range(-128, 127); 1998 return new(zone) Range(-128, 127);
1913 case EXTERNAL_UNSIGNED_BYTE_ELEMENTS: 1999 case EXTERNAL_UNSIGNED_BYTE_ELEMENTS:
1914 return new(zone) Range(0, 255); 2000 return new(zone) Range(0, 255);
1915 case EXTERNAL_SHORT_ELEMENTS: 2001 case EXTERNAL_SHORT_ELEMENTS:
1916 return new(zone) Range(-32768, 32767); 2002 return new(zone) Range(-32768, 32767);
(...skipping 1024 matching lines...) Expand 10 before | Expand all | Expand 10 after
2941 3027
2942 3028
2943 void HCheckFunction::Verify() { 3029 void HCheckFunction::Verify() {
2944 HInstruction::Verify(); 3030 HInstruction::Verify();
2945 ASSERT(HasNoUses()); 3031 ASSERT(HasNoUses());
2946 } 3032 }
2947 3033
2948 #endif 3034 #endif
2949 3035
2950 } } // namespace v8::internal 3036 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698