OLD | NEW |
---|---|
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/compiler/typer.h" | 5 #include "src/compiler/typer.h" |
6 | 6 |
7 #include <iomanip> | 7 #include <iomanip> |
8 | 8 |
9 #include "src/base/flags.h" | 9 #include "src/base/flags.h" |
10 #include "src/bootstrapper.h" | 10 #include "src/bootstrapper.h" |
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
644 // the increment, just return the initial value's type. | 644 // the increment, just return the initial value's type. |
645 if (!initial_type->IsInhabited() || !increment_type->IsInhabited()) { | 645 if (!initial_type->IsInhabited() || !increment_type->IsInhabited()) { |
646 return initial_type; | 646 return initial_type; |
647 } | 647 } |
648 | 648 |
649 // Now process the bounds. | 649 // Now process the bounds. |
650 auto res = induction_vars_->induction_variables().find(node->id()); | 650 auto res = induction_vars_->induction_variables().find(node->id()); |
651 DCHECK(res != induction_vars_->induction_variables().end()); | 651 DCHECK(res != induction_vars_->induction_variables().end()); |
652 InductionVariable* induction_var = res->second; | 652 InductionVariable* induction_var = res->second; |
653 | 653 |
654 InductionVariable::ArithmeticType arithmetic_type = induction_var->Type(); | |
655 | |
654 double min = -V8_INFINITY; | 656 double min = -V8_INFINITY; |
655 double max = V8_INFINITY; | 657 double max = V8_INFINITY; |
656 if (increment_type->Min() >= 0) { | 658 |
659 double increment_min; | |
660 double increment_max; | |
661 if (arithmetic_type == InductionVariable::ArithmeticType::kAddition) { | |
662 increment_min = increment_type->Min(); | |
663 increment_max = increment_type->Max(); | |
664 } else { | |
665 DCHECK(arithmetic_type == InductionVariable::ArithmeticType::kSubtraction); | |
666 increment_min = -increment_type->Max(); | |
667 increment_max = -increment_type->Min(); | |
668 } | |
669 | |
670 if ((increment_type->Min() >= 0 && | |
671 arithmetic_type == InductionVariable::ArithmeticType::kAddition) || | |
672 (increment_type->Max() <= 0 && | |
673 arithmetic_type == InductionVariable::ArithmeticType::kSubtraction)) { | |
Jarin
2016/08/22 07:27:20
How about
if (increment_min >= 0) {
Franzi
2016/08/22 09:06:30
Thanks!
| |
674 // increasing sequence (add positive values, or subtract negative values) | |
657 min = initial_type->Min(); | 675 min = initial_type->Min(); |
658 for (auto bound : induction_var->upper_bounds()) { | 676 for (auto bound : induction_var->upper_bounds()) { |
659 Type* bound_type = TypeOrNone(bound.bound); | 677 Type* bound_type = TypeOrNone(bound.bound); |
660 // If the type is not an integer, just skip the bound. | 678 // If the type is not an integer, just skip the bound. |
661 if (!bound_type->Is(typer_->cache_.kInteger)) continue; | 679 if (!bound_type->Is(typer_->cache_.kInteger)) continue; |
662 // If the type is not inhabited, then we can take the initial value. | 680 // If the type is not inhabited, then we can take the initial value. |
663 if (!bound_type->IsInhabited()) { | 681 if (!bound_type->IsInhabited()) { |
664 max = initial_type->Max(); | 682 max = initial_type->Max(); |
665 break; | 683 break; |
666 } | 684 } |
667 double bound_max = bound_type->Max(); | 685 double bound_max = bound_type->Max(); |
668 if (bound.kind == InductionVariable::kStrict) { | 686 if (bound.kind == InductionVariable::kStrict) { |
669 bound_max -= 1; | 687 bound_max -= 1; |
670 } | 688 } |
671 max = std::min(max, bound_max + increment_type->Max()); | 689 max = std::min(max, bound_max + increment_max); |
672 } | 690 } |
673 // The upper bound must be at least the initial value's upper bound. | 691 // The upper bound must be at least the initial value's upper bound. |
674 max = std::max(max, initial_type->Max()); | 692 max = std::max(max, initial_type->Max()); |
675 } else if (increment_type->Max() <= 0) { | 693 } else if ((increment_type->Max() <= 0 && |
694 arithmetic_type == | |
695 InductionVariable::ArithmeticType::kAddition) || | |
696 (increment_type->Min() >= 0 && | |
697 arithmetic_type == | |
698 InductionVariable::ArithmeticType::kSubtraction)) { | |
699 // decreasing sequence (add negative values, or subtract positive values) | |
Jarin
2016/08/22 07:27:19
} else if (increment_max <= 0) {
Franzi
2016/08/22 09:06:30
Done.
| |
676 max = initial_type->Max(); | 700 max = initial_type->Max(); |
677 for (auto bound : induction_var->lower_bounds()) { | 701 for (auto bound : induction_var->lower_bounds()) { |
678 Type* bound_type = TypeOrNone(bound.bound); | 702 Type* bound_type = TypeOrNone(bound.bound); |
679 // If the type is not an integer, just skip the bound. | 703 // If the type is not an integer, just skip the bound. |
680 if (!bound_type->Is(typer_->cache_.kInteger)) continue; | 704 if (!bound_type->Is(typer_->cache_.kInteger)) continue; |
681 // If the type is not inhabited, then we can take the initial value. | 705 // If the type is not inhabited, then we can take the initial value. |
682 if (!bound_type->IsInhabited()) { | 706 if (!bound_type->IsInhabited()) { |
683 min = initial_type->Min(); | 707 min = initial_type->Min(); |
684 break; | 708 break; |
685 } | 709 } |
686 double bound_min = bound_type->Min(); | 710 double bound_min = bound_type->Min(); |
687 if (bound.kind == InductionVariable::kStrict) { | 711 if (bound.kind == InductionVariable::kStrict) { |
688 bound_min += 1; | 712 bound_min += 1; |
689 } | 713 } |
690 min = std::max(min, bound_min + increment_type->Min()); | 714 min = std::max(min, bound_min + increment_min); |
691 } | 715 } |
692 // The lower bound must be at most the initial value's lower bound. | 716 // The lower bound must be at most the initial value's lower bound. |
693 min = std::min(min, initial_type->Min()); | 717 min = std::min(min, initial_type->Min()); |
694 } else { | 718 } else { |
695 // Shortcut: If the increment can be both positive and negative, | 719 // Shortcut: If the increment can be both positive and negative, |
696 // the variable can go arbitrarily far, so just return integer. | 720 // the variable can go arbitrarily far, so just return integer. |
697 return typer_->cache_.kInteger; | 721 return typer_->cache_.kInteger; |
698 } | 722 } |
699 if (FLAG_trace_turbo_loop) { | 723 if (FLAG_trace_turbo_loop) { |
700 OFStream os(stdout); | 724 OFStream os(stdout); |
701 os << std::setprecision(10); | 725 os << std::setprecision(10); |
702 os << "Loop (" << NodeProperties::GetControlInput(node)->id() | 726 os << "Loop (" << NodeProperties::GetControlInput(node)->id() |
703 << ") variable bounds for phi " << node->id() << ": (" << min << ", " | 727 << ") variable bounds in " |
704 << max << ")\n"; | 728 << (arithmetic_type == InductionVariable::ArithmeticType::kAddition |
729 ? "addition" | |
730 : "subtraction") | |
731 << " for phi " << node->id() << ": (" << min << ", " << max << ")\n"; | |
705 } | 732 } |
706 return Type::Range(min, max, typer_->zone()); | 733 return Type::Range(min, max, typer_->zone()); |
707 } | 734 } |
708 | 735 |
709 Type* Typer::Visitor::TypeEffectPhi(Node* node) { | 736 Type* Typer::Visitor::TypeEffectPhi(Node* node) { |
710 UNREACHABLE(); | 737 UNREACHABLE(); |
711 return nullptr; | 738 return nullptr; |
712 } | 739 } |
713 | 740 |
714 Type* Typer::Visitor::TypeLoopExit(Node* node) { | 741 Type* Typer::Visitor::TypeLoopExit(Node* node) { |
(...skipping 1606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2321 } | 2348 } |
2322 if (Type::IsInteger(*value)) { | 2349 if (Type::IsInteger(*value)) { |
2323 return Type::Range(value->Number(), value->Number(), zone()); | 2350 return Type::Range(value->Number(), value->Number(), zone()); |
2324 } | 2351 } |
2325 return Type::Constant(value, zone()); | 2352 return Type::Constant(value, zone()); |
2326 } | 2353 } |
2327 | 2354 |
2328 } // namespace compiler | 2355 } // namespace compiler |
2329 } // namespace internal | 2356 } // namespace internal |
2330 } // namespace v8 | 2357 } // namespace v8 |
OLD | NEW |