| 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> |
| 8 |
| 7 #include "src/base/flags.h" | 9 #include "src/base/flags.h" |
| 8 #include "src/bootstrapper.h" | 10 #include "src/bootstrapper.h" |
| 9 #include "src/compiler/common-operator.h" | 11 #include "src/compiler/common-operator.h" |
| 10 #include "src/compiler/graph-reducer.h" | 12 #include "src/compiler/graph-reducer.h" |
| 11 #include "src/compiler/js-operator.h" | 13 #include "src/compiler/js-operator.h" |
| 12 #include "src/compiler/loop-variable-optimizer.h" | 14 #include "src/compiler/loop-variable-optimizer.h" |
| 13 #include "src/compiler/node-properties.h" | 15 #include "src/compiler/node-properties.h" |
| 14 #include "src/compiler/node.h" | 16 #include "src/compiler/node.h" |
| 15 #include "src/compiler/operation-typer.h" | 17 #include "src/compiler/operation-typer.h" |
| 16 #include "src/compiler/simplified-operator.h" | 18 #include "src/compiler/simplified-operator.h" |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 if (induction_vars != nullptr) { | 313 if (induction_vars != nullptr) { |
| 312 induction_vars->ChangeToInductionVariablePhis(); | 314 induction_vars->ChangeToInductionVariablePhis(); |
| 313 } | 315 } |
| 314 Visitor visitor(this, induction_vars); | 316 Visitor visitor(this, induction_vars); |
| 315 GraphReducer graph_reducer(zone(), graph()); | 317 GraphReducer graph_reducer(zone(), graph()); |
| 316 graph_reducer.AddReducer(&visitor); | 318 graph_reducer.AddReducer(&visitor); |
| 317 for (Node* const root : roots) graph_reducer.ReduceNode(root); | 319 for (Node* const root : roots) graph_reducer.ReduceNode(root); |
| 318 graph_reducer.ReduceGraph(); | 320 graph_reducer.ReduceGraph(); |
| 319 | 321 |
| 320 if (induction_vars != nullptr) { | 322 if (induction_vars != nullptr) { |
| 321 induction_vars->ChangeFromInductionVariablePhis(); | 323 induction_vars->ChangeToPhisAndInsertSigmas(); |
| 322 } | 324 } |
| 323 } | 325 } |
| 324 | 326 |
| 325 void Typer::Decorator::Decorate(Node* node) { | 327 void Typer::Decorator::Decorate(Node* node) { |
| 326 if (node->op()->ValueOutputCount() > 0) { | 328 if (node->op()->ValueOutputCount() > 0) { |
| 327 // Only eagerly type-decorate nodes with known input types. | 329 // Only eagerly type-decorate nodes with known input types. |
| 328 // Other cases will generally require a proper fixpoint iteration with Run. | 330 // Other cases will generally require a proper fixpoint iteration with Run. |
| 329 bool is_typed = NodeProperties::IsTyped(node); | 331 bool is_typed = NodeProperties::IsTyped(node); |
| 330 if (is_typed || NodeProperties::AllValueInputsAreTyped(node)) { | 332 if (is_typed || NodeProperties::AllValueInputsAreTyped(node)) { |
| 331 Visitor typing(typer_, nullptr); | 333 Visitor typing(typer_, nullptr); |
| (...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 816 } | 818 } |
| 817 // The lower bound must be at most the initial value's lower bound. | 819 // The lower bound must be at most the initial value's lower bound. |
| 818 min = std::min(min, initial_type->Min()); | 820 min = std::min(min, initial_type->Min()); |
| 819 } else { | 821 } else { |
| 820 // Shortcut: If the increment can be both positive and negative, | 822 // Shortcut: If the increment can be both positive and negative, |
| 821 // the variable can go arbitrarily far, so just return integer. | 823 // the variable can go arbitrarily far, so just return integer. |
| 822 return typer_->cache_.kInteger; | 824 return typer_->cache_.kInteger; |
| 823 } | 825 } |
| 824 if (FLAG_trace_turbo_loop) { | 826 if (FLAG_trace_turbo_loop) { |
| 825 OFStream os(stdout); | 827 OFStream os(stdout); |
| 828 os << std::setprecision(10); |
| 826 os << "Loop (" << NodeProperties::GetControlInput(node)->id() | 829 os << "Loop (" << NodeProperties::GetControlInput(node)->id() |
| 827 << ") variable bounds for phi " << node->id() << ": (" << min << ", " | 830 << ") variable bounds for phi " << node->id() << ": (" << min << ", " |
| 828 << max << ")\n"; | 831 << max << ")\n"; |
| 829 } | 832 } |
| 830 return Type::Range(min, max, typer_->zone()); | 833 return Type::Range(min, max, typer_->zone()); |
| 831 } | 834 } |
| 832 | 835 |
| 833 Type* Typer::Visitor::TypeEffectPhi(Node* node) { | 836 Type* Typer::Visitor::TypeEffectPhi(Node* node) { |
| 834 UNREACHABLE(); | 837 UNREACHABLE(); |
| 835 return nullptr; | 838 return nullptr; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 886 Type* Typer::Visitor::TypeProjection(Node* node) { | 889 Type* Typer::Visitor::TypeProjection(Node* node) { |
| 887 Type* const type = Operand(node, 0); | 890 Type* const type = Operand(node, 0); |
| 888 if (type->Is(Type::None())) return Type::None(); | 891 if (type->Is(Type::None())) return Type::None(); |
| 889 int const index = static_cast<int>(ProjectionIndexOf(node->op())); | 892 int const index = static_cast<int>(ProjectionIndexOf(node->op())); |
| 890 if (type->IsTuple() && index < type->AsTuple()->Arity()) { | 893 if (type->IsTuple() && index < type->AsTuple()->Arity()) { |
| 891 return type->AsTuple()->Element(index); | 894 return type->AsTuple()->Element(index); |
| 892 } | 895 } |
| 893 return Type::Any(); | 896 return Type::Any(); |
| 894 } | 897 } |
| 895 | 898 |
| 899 Type* Typer::Visitor::TypeSigma(Node* node) { |
| 900 Type* const type = Operand(node, 0); |
| 901 return typer_->operation_typer()->TypeSigma(node->op(), type); |
| 902 } |
| 903 |
| 896 Type* Typer::Visitor::TypeDead(Node* node) { return Type::None(); } | 904 Type* Typer::Visitor::TypeDead(Node* node) { return Type::None(); } |
| 897 | 905 |
| 898 // JS comparison operators. | 906 // JS comparison operators. |
| 899 | 907 |
| 900 | 908 |
| 901 Type* Typer::Visitor::JSEqualTyper(Type* lhs, Type* rhs, Typer* t) { | 909 Type* Typer::Visitor::JSEqualTyper(Type* lhs, Type* rhs, Typer* t) { |
| 902 if (lhs->Is(Type::NaN()) || rhs->Is(Type::NaN())) return t->singleton_false_; | 910 if (lhs->Is(Type::NaN()) || rhs->Is(Type::NaN())) return t->singleton_false_; |
| 903 if (lhs->Is(Type::NullOrUndefined()) && rhs->Is(Type::NullOrUndefined())) { | 911 if (lhs->Is(Type::NullOrUndefined()) && rhs->Is(Type::NullOrUndefined())) { |
| 904 return t->singleton_true_; | 912 return t->singleton_true_; |
| 905 } | 913 } |
| (...skipping 1763 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2669 } | 2677 } |
| 2670 if (Type::IsInteger(*value)) { | 2678 if (Type::IsInteger(*value)) { |
| 2671 return Type::Range(value->Number(), value->Number(), zone()); | 2679 return Type::Range(value->Number(), value->Number(), zone()); |
| 2672 } | 2680 } |
| 2673 return Type::Constant(value, zone()); | 2681 return Type::Constant(value, zone()); |
| 2674 } | 2682 } |
| 2675 | 2683 |
| 2676 } // namespace compiler | 2684 } // namespace compiler |
| 2677 } // namespace internal | 2685 } // namespace internal |
| 2678 } // namespace v8 | 2686 } // namespace v8 |
| OLD | NEW |