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

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

Issue 12211041: Infrastructure classes for evaluating numeric relations between values. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Added relations implied by conditional branches. 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
« no previous file with comments | « src/hydrogen-instructions.h ('k') | src/ia32/lithium-ia32.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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());
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 641 matching lines...) Expand 10 before | Expand all | Expand 10 after
1469 if (!right()->range()->CanBeZero()) { 1521 if (!right()->range()->CanBeZero()) {
1470 ClearFlag(HValue::kCanBeDivByZero); 1522 ClearFlag(HValue::kCanBeDivByZero);
1471 } 1523 }
1472 return result; 1524 return result;
1473 } else { 1525 } else {
1474 return HValue::InferRange(zone); 1526 return HValue::InferRange(zone);
1475 } 1527 }
1476 } 1528 }
1477 1529
1478 1530
1531 void HPhi::AddInformativeDefinitions() {
1532 HValue* induction_base = NULL;
1533 NumericRelation relation = NumericRelation::None();
1534 if (OperandCount() == 2) {
1535 if (OperandAt(0)->IsRelationTrue(NumericRelation::Ge(), this)) {
1536 induction_base = OperandAt(1);
1537 relation = NumericRelation::Ge();
1538 } else if (OperandAt(0)->IsRelationTrue(NumericRelation::Le(), this)) {
1539 induction_base = OperandAt(1);
1540 relation = NumericRelation::Ge();
1541 } else if (OperandAt(1)->IsRelationTrue(NumericRelation::Ge(), this)) {
1542 induction_base = OperandAt(0);
1543 relation = NumericRelation::Ge();
1544 } else if (OperandAt(1)->IsRelationTrue(NumericRelation::Le(), this)) {
1545 induction_base = OperandAt(0);
1546 relation = NumericRelation::Ge();
1547 }
1548 }
1549
1550 if (induction_base == NULL) return;
1551
1552 AddNumericConstraint(block()->first(), induction_base, relation);
1553 }
1554
1555
1479 Range* HMathMinMax::InferRange(Zone* zone) { 1556 Range* HMathMinMax::InferRange(Zone* zone) {
1480 if (representation().IsInteger32()) { 1557 if (representation().IsInteger32()) {
1481 Range* a = left()->range(); 1558 Range* a = left()->range();
1482 Range* b = right()->range(); 1559 Range* b = right()->range();
1483 Range* res = a->Copy(zone); 1560 Range* res = a->Copy(zone);
1484 if (operation_ == kMathMax) { 1561 if (operation_ == kMathMax) {
1485 res->CombinedMax(b); 1562 res->CombinedMax(b);
1486 } else { 1563 } else {
1487 ASSERT(operation_ == kMathMin); 1564 ASSERT(operation_ == kMathMin);
1488 res->CombinedMin(b); 1565 res->CombinedMin(b);
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
1930 } 2007 }
1931 2008
1932 2009
1933 void HStringCompareAndBranch::PrintDataTo(StringStream* stream) { 2010 void HStringCompareAndBranch::PrintDataTo(StringStream* stream) {
1934 stream->Add(Token::Name(token())); 2011 stream->Add(Token::Name(token()));
1935 stream->Add(" "); 2012 stream->Add(" ");
1936 HControlInstruction::PrintDataTo(stream); 2013 HControlInstruction::PrintDataTo(stream);
1937 } 2014 }
1938 2015
1939 2016
2017 void HCompareIDAndBranch::AddInformativeDefinitions() {
2018 NumericRelation r = NumericRelation::FromToken(token());
2019 if (r == NumericRelation::None()) return;
2020
2021 left()->AddNumericConstraint(SuccessorAt(0)->first(), right(), r);
2022 left()->AddNumericConstraint(SuccessorAt(1)->first(), right(), r.Reversed());
2023 }
2024
2025
1940 void HCompareIDAndBranch::PrintDataTo(StringStream* stream) { 2026 void HCompareIDAndBranch::PrintDataTo(StringStream* stream) {
1941 stream->Add(Token::Name(token())); 2027 stream->Add(Token::Name(token()));
1942 stream->Add(" "); 2028 stream->Add(" ");
1943 left()->PrintNameTo(stream); 2029 left()->PrintNameTo(stream);
1944 stream->Add(" "); 2030 stream->Add(" ");
1945 right()->PrintNameTo(stream); 2031 right()->PrintNameTo(stream);
1946 HControlInstruction::PrintDataTo(stream); 2032 HControlInstruction::PrintDataTo(stream);
1947 } 2033 }
1948 2034
1949 2035
(...skipping 984 matching lines...) Expand 10 before | Expand all | Expand 10 after
2934 3020
2935 3021
2936 void HCheckFunction::Verify() { 3022 void HCheckFunction::Verify() {
2937 HInstruction::Verify(); 3023 HInstruction::Verify();
2938 ASSERT(HasNoUses()); 3024 ASSERT(HasNoUses());
2939 } 3025 }
2940 3026
2941 #endif 3027 #endif
2942 3028
2943 } } // namespace v8::internal 3029 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/hydrogen-instructions.h ('k') | src/ia32/lithium-ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698