| 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 "src/base/flags.h" | 7 #include "src/base/flags.h" |
| 8 #include "src/bootstrapper.h" | 8 #include "src/bootstrapper.h" |
| 9 #include "src/compilation-dependencies.h" | 9 #include "src/compilation-dependencies.h" |
| 10 #include "src/compiler/common-operator.h" | 10 #include "src/compiler/common-operator.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 Type::MinusZeroOrNaN(), zone); | 50 Type::MinusZeroOrNaN(), zone); |
| 51 DCHECK(!truncating_to_zero->Maybe(Type::Integral32())); | 51 DCHECK(!truncating_to_zero->Maybe(Type::Integral32())); |
| 52 | 52 |
| 53 singleton_false_ = Type::Constant(factory->false_value(), zone); | 53 singleton_false_ = Type::Constant(factory->false_value(), zone); |
| 54 singleton_true_ = Type::Constant(factory->true_value(), zone); | 54 singleton_true_ = Type::Constant(factory->true_value(), zone); |
| 55 singleton_the_hole_ = Type::Constant(factory->the_hole_value(), zone); | 55 singleton_the_hole_ = Type::Constant(factory->the_hole_value(), zone); |
| 56 signed32ish_ = Type::Union(Type::Signed32(), truncating_to_zero, zone); | 56 signed32ish_ = Type::Union(Type::Signed32(), truncating_to_zero, zone); |
| 57 unsigned32ish_ = Type::Union(Type::Unsigned32(), truncating_to_zero, zone); | 57 unsigned32ish_ = Type::Union(Type::Unsigned32(), truncating_to_zero, zone); |
| 58 falsish_ = Type::Union( | 58 falsish_ = Type::Union( |
| 59 Type::Undetectable(), | 59 Type::Undetectable(), |
| 60 Type::Union( | 60 Type::Union(Type::Union(singleton_false_, cache_.kZeroish, zone), |
| 61 Type::Union(Type::Union(singleton_false_, cache_.kZeroish, zone), | 61 singleton_the_hole_, zone), |
| 62 Type::NullOrUndefined(), zone), | |
| 63 singleton_the_hole_, zone), | |
| 64 zone); | 62 zone); |
| 65 truish_ = Type::Union( | 63 truish_ = Type::Union( |
| 66 singleton_true_, | 64 singleton_true_, |
| 67 Type::Union(Type::DetectableReceiver(), Type::Symbol(), zone), zone); | 65 Type::Union(Type::DetectableReceiver(), Type::Symbol(), zone), zone); |
| 68 | 66 |
| 69 decorator_ = new (zone) Decorator(this); | 67 decorator_ = new (zone) Decorator(this); |
| 70 graph_->AddDecorator(decorator_); | 68 graph_->AddDecorator(decorator_); |
| 71 } | 69 } |
| 72 | 70 |
| 73 | 71 |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 static Type* ToName(Type*, Typer*); | 235 static Type* ToName(Type*, Typer*); |
| 238 static Type* ToNumber(Type*, Typer*); | 236 static Type* ToNumber(Type*, Typer*); |
| 239 static Type* ToObject(Type*, Typer*); | 237 static Type* ToObject(Type*, Typer*); |
| 240 static Type* ToString(Type*, Typer*); | 238 static Type* ToString(Type*, Typer*); |
| 241 static Type* NumberToInt32(Type*, Typer*); | 239 static Type* NumberToInt32(Type*, Typer*); |
| 242 static Type* NumberToUint32(Type*, Typer*); | 240 static Type* NumberToUint32(Type*, Typer*); |
| 243 | 241 |
| 244 static Type* ObjectIsNumber(Type*, Typer*); | 242 static Type* ObjectIsNumber(Type*, Typer*); |
| 245 static Type* ObjectIsReceiver(Type*, Typer*); | 243 static Type* ObjectIsReceiver(Type*, Typer*); |
| 246 static Type* ObjectIsSmi(Type*, Typer*); | 244 static Type* ObjectIsSmi(Type*, Typer*); |
| 245 static Type* ObjectIsUndetectable(Type*, Typer*); |
| 247 | 246 |
| 248 static Type* JSAddRanger(RangeType*, RangeType*, Typer*); | 247 static Type* JSAddRanger(RangeType*, RangeType*, Typer*); |
| 249 static Type* JSSubtractRanger(RangeType*, RangeType*, Typer*); | 248 static Type* JSSubtractRanger(RangeType*, RangeType*, Typer*); |
| 250 static Type* JSDivideRanger(RangeType*, RangeType*, Typer*); | 249 static Type* JSDivideRanger(RangeType*, RangeType*, Typer*); |
| 251 static Type* JSModulusRanger(RangeType*, RangeType*, Typer*); | 250 static Type* JSModulusRanger(RangeType*, RangeType*, Typer*); |
| 252 | 251 |
| 253 static ComparisonOutcome JSCompareTyper(Type*, Type*, Typer*); | 252 static ComparisonOutcome JSCompareTyper(Type*, Type*, Typer*); |
| 254 | 253 |
| 255 #define DECLARE_METHOD(x) static Type* x##Typer(Type*, Type*, Typer*); | 254 #define DECLARE_METHOD(x) static Type* x##Typer(Type*, Type*, Typer*); |
| 256 JS_SIMPLE_BINOP_LIST(DECLARE_METHOD) | 255 JS_SIMPLE_BINOP_LIST(DECLARE_METHOD) |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 } | 461 } |
| 463 return Type::Number(); | 462 return Type::Number(); |
| 464 } | 463 } |
| 465 | 464 |
| 466 | 465 |
| 467 // static | 466 // static |
| 468 Type* Typer::Visitor::ToObject(Type* type, Typer* t) { | 467 Type* Typer::Visitor::ToObject(Type* type, Typer* t) { |
| 469 // ES6 section 7.1.13 ToObject ( argument ) | 468 // ES6 section 7.1.13 ToObject ( argument ) |
| 470 if (type->Is(Type::Receiver())) return type; | 469 if (type->Is(Type::Receiver())) return type; |
| 471 if (type->Is(Type::Primitive())) return Type::OtherObject(); | 470 if (type->Is(Type::Primitive())) return Type::OtherObject(); |
| 472 if (!type->Maybe(Type::Undetectable())) return Type::DetectableReceiver(); | 471 if (!type->Maybe(Type::OtherUndetectable())) { |
| 472 return Type::DetectableReceiver(); |
| 473 } |
| 473 return Type::Receiver(); | 474 return Type::Receiver(); |
| 474 } | 475 } |
| 475 | 476 |
| 476 | 477 |
| 477 // static | 478 // static |
| 478 Type* Typer::Visitor::ToString(Type* type, Typer* t) { | 479 Type* Typer::Visitor::ToString(Type* type, Typer* t) { |
| 479 // ES6 section 7.1.12 ToString ( argument ) | 480 // ES6 section 7.1.12 ToString ( argument ) |
| 480 type = ToPrimitive(type, t); | 481 type = ToPrimitive(type, t); |
| 481 if (type->Is(Type::String())) return type; | 482 if (type->Is(Type::String())) return type; |
| 482 return Type::String(); | 483 return Type::String(); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 } | 527 } |
| 527 | 528 |
| 528 | 529 |
| 529 Type* Typer::Visitor::ObjectIsSmi(Type* type, Typer* t) { | 530 Type* Typer::Visitor::ObjectIsSmi(Type* type, Typer* t) { |
| 530 if (type->Is(Type::TaggedSigned())) return t->singleton_true_; | 531 if (type->Is(Type::TaggedSigned())) return t->singleton_true_; |
| 531 if (type->Is(Type::TaggedPointer())) return t->singleton_false_; | 532 if (type->Is(Type::TaggedPointer())) return t->singleton_false_; |
| 532 return Type::Boolean(); | 533 return Type::Boolean(); |
| 533 } | 534 } |
| 534 | 535 |
| 535 | 536 |
| 537 Type* Typer::Visitor::ObjectIsUndetectable(Type* type, Typer* t) { |
| 538 if (type->Is(Type::Undetectable())) return t->singleton_true_; |
| 539 if (!type->Maybe(Type::Undetectable())) return t->singleton_false_; |
| 540 return Type::Boolean(); |
| 541 } |
| 542 |
| 543 |
| 536 // ----------------------------------------------------------------------------- | 544 // ----------------------------------------------------------------------------- |
| 537 | 545 |
| 538 | 546 |
| 539 // Control operators. | 547 // Control operators. |
| 540 | 548 |
| 541 Type* Typer::Visitor::TypeStart(Node* node) { return Type::Internal(); } | 549 Type* Typer::Visitor::TypeStart(Node* node) { return Type::Internal(); } |
| 542 | 550 |
| 543 Type* Typer::Visitor::TypeIfException(Node* node) { return Type::Any(); } | 551 Type* Typer::Visitor::TypeIfException(Node* node) { return Type::Any(); } |
| 544 | 552 |
| 545 | 553 |
| (...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1164 Type* Typer::Visitor::JSTypeOfTyper(Type* type, Typer* t) { | 1172 Type* Typer::Visitor::JSTypeOfTyper(Type* type, Typer* t) { |
| 1165 Factory* const f = t->isolate()->factory(); | 1173 Factory* const f = t->isolate()->factory(); |
| 1166 if (type->Is(Type::Boolean())) { | 1174 if (type->Is(Type::Boolean())) { |
| 1167 return Type::Constant(f->boolean_string(), t->zone()); | 1175 return Type::Constant(f->boolean_string(), t->zone()); |
| 1168 } else if (type->Is(Type::Number())) { | 1176 } else if (type->Is(Type::Number())) { |
| 1169 return Type::Constant(f->number_string(), t->zone()); | 1177 return Type::Constant(f->number_string(), t->zone()); |
| 1170 } else if (type->Is(Type::String())) { | 1178 } else if (type->Is(Type::String())) { |
| 1171 return Type::Constant(f->string_string(), t->zone()); | 1179 return Type::Constant(f->string_string(), t->zone()); |
| 1172 } else if (type->Is(Type::Symbol())) { | 1180 } else if (type->Is(Type::Symbol())) { |
| 1173 return Type::Constant(f->symbol_string(), t->zone()); | 1181 return Type::Constant(f->symbol_string(), t->zone()); |
| 1174 } else if (type->Is(Type::Union(Type::Undefined(), Type::Undetectable(), | 1182 } else if (type->Is(Type::Union(Type::Undefined(), Type::OtherUndetectable(), |
| 1175 t->zone()))) { | 1183 t->zone()))) { |
| 1176 return Type::Constant(f->undefined_string(), t->zone()); | 1184 return Type::Constant(f->undefined_string(), t->zone()); |
| 1177 } else if (type->Is(Type::Null())) { | 1185 } else if (type->Is(Type::Null())) { |
| 1178 return Type::Constant(f->object_string(), t->zone()); | 1186 return Type::Constant(f->object_string(), t->zone()); |
| 1179 } else if (type->Is(Type::Function())) { | 1187 } else if (type->Is(Type::Function())) { |
| 1180 return Type::Constant(f->function_string(), t->zone()); | 1188 return Type::Constant(f->function_string(), t->zone()); |
| 1181 } else if (type->IsConstant()) { | 1189 } else if (type->IsConstant()) { |
| 1182 return Type::Constant( | 1190 return Type::Constant( |
| 1183 Object::TypeOf(t->isolate(), type->AsConstant()->Value()), t->zone()); | 1191 Object::TypeOf(t->isolate(), type->AsConstant()->Value()), t->zone()); |
| 1184 } | 1192 } |
| (...skipping 733 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1918 Type* Typer::Visitor::TypeObjectIsReceiver(Node* node) { | 1926 Type* Typer::Visitor::TypeObjectIsReceiver(Node* node) { |
| 1919 return TypeUnaryOp(node, ObjectIsReceiver); | 1927 return TypeUnaryOp(node, ObjectIsReceiver); |
| 1920 } | 1928 } |
| 1921 | 1929 |
| 1922 | 1930 |
| 1923 Type* Typer::Visitor::TypeObjectIsSmi(Node* node) { | 1931 Type* Typer::Visitor::TypeObjectIsSmi(Node* node) { |
| 1924 return TypeUnaryOp(node, ObjectIsSmi); | 1932 return TypeUnaryOp(node, ObjectIsSmi); |
| 1925 } | 1933 } |
| 1926 | 1934 |
| 1927 | 1935 |
| 1936 Type* Typer::Visitor::TypeObjectIsUndetectable(Node* node) { |
| 1937 return TypeUnaryOp(node, ObjectIsUndetectable); |
| 1938 } |
| 1939 |
| 1940 |
| 1928 // Machine operators. | 1941 // Machine operators. |
| 1929 | 1942 |
| 1930 Type* Typer::Visitor::TypeLoad(Node* node) { return Type::Any(); } | 1943 Type* Typer::Visitor::TypeLoad(Node* node) { return Type::Any(); } |
| 1931 | 1944 |
| 1932 Type* Typer::Visitor::TypeStackSlot(Node* node) { return Type::Any(); } | 1945 Type* Typer::Visitor::TypeStackSlot(Node* node) { return Type::Any(); } |
| 1933 | 1946 |
| 1934 Type* Typer::Visitor::TypeStore(Node* node) { | 1947 Type* Typer::Visitor::TypeStore(Node* node) { |
| 1935 UNREACHABLE(); | 1948 UNREACHABLE(); |
| 1936 return nullptr; | 1949 return nullptr; |
| 1937 } | 1950 } |
| (...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2443 } | 2456 } |
| 2444 if (Type::IsInteger(*value)) { | 2457 if (Type::IsInteger(*value)) { |
| 2445 return Type::Range(value->Number(), value->Number(), zone()); | 2458 return Type::Range(value->Number(), value->Number(), zone()); |
| 2446 } | 2459 } |
| 2447 return Type::Constant(value, zone()); | 2460 return Type::Constant(value, zone()); |
| 2448 } | 2461 } |
| 2449 | 2462 |
| 2450 } // namespace compiler | 2463 } // namespace compiler |
| 2451 } // namespace internal | 2464 } // namespace internal |
| 2452 } // namespace v8 | 2465 } // namespace v8 |
| OLD | NEW |