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 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 static Type* ToBoolean(Type*, Typer*); | 234 static Type* ToBoolean(Type*, Typer*); |
235 static Type* ToInteger(Type*, Typer*); | 235 static Type* ToInteger(Type*, Typer*); |
236 static Type* ToLength(Type*, Typer*); | 236 static Type* ToLength(Type*, Typer*); |
237 static Type* ToName(Type*, Typer*); | 237 static Type* ToName(Type*, Typer*); |
238 static Type* ToNumber(Type*, Typer*); | 238 static Type* ToNumber(Type*, Typer*); |
239 static Type* ToObject(Type*, Typer*); | 239 static Type* ToObject(Type*, Typer*); |
240 static Type* ToString(Type*, Typer*); | 240 static Type* ToString(Type*, Typer*); |
241 static Type* NumberToInt32(Type*, Typer*); | 241 static Type* NumberToInt32(Type*, Typer*); |
242 static Type* NumberToUint32(Type*, Typer*); | 242 static Type* NumberToUint32(Type*, Typer*); |
243 | 243 |
| 244 static Type* ObjectIsNumber(Type*, Typer*); |
| 245 static Type* ObjectIsReceiver(Type*, Typer*); |
| 246 static Type* ObjectIsSmi(Type*, Typer*); |
| 247 |
244 static Type* JSAddRanger(RangeType*, RangeType*, Typer*); | 248 static Type* JSAddRanger(RangeType*, RangeType*, Typer*); |
245 static Type* JSSubtractRanger(RangeType*, RangeType*, Typer*); | 249 static Type* JSSubtractRanger(RangeType*, RangeType*, Typer*); |
246 static Type* JSDivideRanger(RangeType*, RangeType*, Typer*); | 250 static Type* JSDivideRanger(RangeType*, RangeType*, Typer*); |
247 static Type* JSModulusRanger(RangeType*, RangeType*, Typer*); | 251 static Type* JSModulusRanger(RangeType*, RangeType*, Typer*); |
248 | 252 |
249 static ComparisonOutcome JSCompareTyper(Type*, Type*, Typer*); | 253 static ComparisonOutcome JSCompareTyper(Type*, Type*, Typer*); |
250 | 254 |
251 #define DECLARE_METHOD(x) static Type* x##Typer(Type*, Type*, Typer*); | 255 #define DECLARE_METHOD(x) static Type* x##Typer(Type*, Type*, Typer*); |
252 JS_SIMPLE_BINOP_LIST(DECLARE_METHOD) | 256 JS_SIMPLE_BINOP_LIST(DECLARE_METHOD) |
253 #undef DECLARE_METHOD | 257 #undef DECLARE_METHOD |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 if (type->Is(t->cache_.kZeroish)) return t->cache_.kSingletonZero; | 502 if (type->Is(t->cache_.kZeroish)) return t->cache_.kSingletonZero; |
499 if (type->Is(t->unsigned32ish_)) { | 503 if (type->Is(t->unsigned32ish_)) { |
500 return Type::Intersect( | 504 return Type::Intersect( |
501 Type::Union(type, t->cache_.kSingletonZero, t->zone()), | 505 Type::Union(type, t->cache_.kSingletonZero, t->zone()), |
502 Type::Unsigned32(), t->zone()); | 506 Type::Unsigned32(), t->zone()); |
503 } | 507 } |
504 return Type::Unsigned32(); | 508 return Type::Unsigned32(); |
505 } | 509 } |
506 | 510 |
507 | 511 |
| 512 // Type checks. |
| 513 |
| 514 |
| 515 Type* Typer::Visitor::ObjectIsNumber(Type* type, Typer* t) { |
| 516 if (type->Is(Type::Number())) return t->singleton_true_; |
| 517 if (!type->Maybe(Type::Number())) return t->singleton_false_; |
| 518 return Type::Boolean(); |
| 519 } |
| 520 |
| 521 |
| 522 Type* Typer::Visitor::ObjectIsReceiver(Type* type, Typer* t) { |
| 523 if (type->Is(Type::Receiver())) return t->singleton_true_; |
| 524 if (!type->Maybe(Type::Receiver())) return t->singleton_false_; |
| 525 return Type::Boolean(); |
| 526 } |
| 527 |
| 528 |
| 529 Type* Typer::Visitor::ObjectIsSmi(Type* type, Typer* t) { |
| 530 if (type->Is(Type::TaggedSigned())) return t->singleton_true_; |
| 531 if (type->Is(Type::TaggedPointer())) return t->singleton_false_; |
| 532 return Type::Boolean(); |
| 533 } |
| 534 |
| 535 |
508 // ----------------------------------------------------------------------------- | 536 // ----------------------------------------------------------------------------- |
509 | 537 |
510 | 538 |
511 // Control operators. | 539 // Control operators. |
512 | 540 |
513 Type* Typer::Visitor::TypeStart(Node* node) { return Type::Internal(); } | 541 Type* Typer::Visitor::TypeStart(Node* node) { return Type::Internal(); } |
514 | 542 |
515 Type* Typer::Visitor::TypeIfException(Node* node) { return Type::Any(); } | 543 Type* Typer::Visitor::TypeIfException(Node* node) { return Type::Any(); } |
516 | 544 |
517 | 545 |
(...skipping 1004 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1522 | 1550 |
1523 Type* Typer::Visitor::TypeJSCallFunction(Node* node) { | 1551 Type* Typer::Visitor::TypeJSCallFunction(Node* node) { |
1524 // TODO(bmeurer): We could infer better types if we wouldn't ignore the | 1552 // TODO(bmeurer): We could infer better types if we wouldn't ignore the |
1525 // argument types for the JSCallFunctionTyper above. | 1553 // argument types for the JSCallFunctionTyper above. |
1526 return TypeUnaryOp(node, JSCallFunctionTyper); | 1554 return TypeUnaryOp(node, JSCallFunctionTyper); |
1527 } | 1555 } |
1528 | 1556 |
1529 | 1557 |
1530 Type* Typer::Visitor::TypeJSCallRuntime(Node* node) { | 1558 Type* Typer::Visitor::TypeJSCallRuntime(Node* node) { |
1531 switch (CallRuntimeParametersOf(node->op()).id()) { | 1559 switch (CallRuntimeParametersOf(node->op()).id()) { |
| 1560 case Runtime::kInlineIsJSReceiver: |
| 1561 return TypeUnaryOp(node, ObjectIsReceiver); |
1532 case Runtime::kInlineIsSmi: | 1562 case Runtime::kInlineIsSmi: |
| 1563 return TypeUnaryOp(node, ObjectIsSmi); |
1533 case Runtime::kInlineIsArray: | 1564 case Runtime::kInlineIsArray: |
1534 case Runtime::kInlineIsDate: | 1565 case Runtime::kInlineIsDate: |
1535 case Runtime::kInlineIsTypedArray: | 1566 case Runtime::kInlineIsTypedArray: |
1536 case Runtime::kInlineIsMinusZero: | 1567 case Runtime::kInlineIsMinusZero: |
1537 case Runtime::kInlineIsRegExp: | 1568 case Runtime::kInlineIsRegExp: |
1538 case Runtime::kInlineIsJSReceiver: | |
1539 return Type::Boolean(); | 1569 return Type::Boolean(); |
1540 case Runtime::kInlineDoubleLo: | 1570 case Runtime::kInlineDoubleLo: |
1541 case Runtime::kInlineDoubleHi: | 1571 case Runtime::kInlineDoubleHi: |
1542 return Type::Signed32(); | 1572 return Type::Signed32(); |
1543 case Runtime::kInlineConstructDouble: | 1573 case Runtime::kInlineConstructDouble: |
1544 case Runtime::kInlineMathFloor: | 1574 case Runtime::kInlineMathFloor: |
1545 case Runtime::kInlineMathSqrt: | 1575 case Runtime::kInlineMathSqrt: |
1546 case Runtime::kInlineMathAcos: | 1576 case Runtime::kInlineMathAcos: |
1547 case Runtime::kInlineMathAsin: | 1577 case Runtime::kInlineMathAsin: |
1548 case Runtime::kInlineMathAtan: | 1578 case Runtime::kInlineMathAtan: |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1871 } | 1901 } |
1872 | 1902 |
1873 | 1903 |
1874 Type* Typer::Visitor::TypeStoreElement(Node* node) { | 1904 Type* Typer::Visitor::TypeStoreElement(Node* node) { |
1875 UNREACHABLE(); | 1905 UNREACHABLE(); |
1876 return nullptr; | 1906 return nullptr; |
1877 } | 1907 } |
1878 | 1908 |
1879 | 1909 |
1880 Type* Typer::Visitor::TypeObjectIsNumber(Node* node) { | 1910 Type* Typer::Visitor::TypeObjectIsNumber(Node* node) { |
1881 Type* arg = Operand(node, 0); | 1911 return TypeUnaryOp(node, ObjectIsNumber); |
1882 if (arg->Is(Type::None())) return Type::None(); | 1912 } |
1883 if (arg->Is(Type::Number())) return typer_->singleton_true_; | 1913 |
1884 if (!arg->Maybe(Type::Number())) return typer_->singleton_false_; | 1914 |
1885 return Type::Boolean(); | 1915 Type* Typer::Visitor::TypeObjectIsReceiver(Node* node) { |
| 1916 return TypeUnaryOp(node, ObjectIsReceiver); |
1886 } | 1917 } |
1887 | 1918 |
1888 | 1919 |
1889 Type* Typer::Visitor::TypeObjectIsSmi(Node* node) { | 1920 Type* Typer::Visitor::TypeObjectIsSmi(Node* node) { |
1890 Type* arg = Operand(node, 0); | 1921 return TypeUnaryOp(node, ObjectIsSmi); |
1891 if (arg->Is(Type::None())) return Type::None(); | |
1892 if (arg->Is(Type::TaggedSigned())) return typer_->singleton_true_; | |
1893 if (arg->Is(Type::TaggedPointer())) return typer_->singleton_false_; | |
1894 return Type::Boolean(); | |
1895 } | 1922 } |
1896 | 1923 |
1897 | 1924 |
1898 // Machine operators. | 1925 // Machine operators. |
1899 | 1926 |
1900 Type* Typer::Visitor::TypeLoad(Node* node) { return Type::Any(); } | 1927 Type* Typer::Visitor::TypeLoad(Node* node) { return Type::Any(); } |
1901 | 1928 |
1902 Type* Typer::Visitor::TypeStackSlot(Node* node) { return Type::Any(); } | 1929 Type* Typer::Visitor::TypeStackSlot(Node* node) { return Type::Any(); } |
1903 | 1930 |
1904 Type* Typer::Visitor::TypeStore(Node* node) { | 1931 Type* Typer::Visitor::TypeStore(Node* node) { |
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2389 } | 2416 } |
2390 if (Type::IsInteger(*value)) { | 2417 if (Type::IsInteger(*value)) { |
2391 return Type::Range(value->Number(), value->Number(), zone()); | 2418 return Type::Range(value->Number(), value->Number(), zone()); |
2392 } | 2419 } |
2393 return Type::Constant(value, zone()); | 2420 return Type::Constant(value, zone()); |
2394 } | 2421 } |
2395 | 2422 |
2396 } // namespace compiler | 2423 } // namespace compiler |
2397 } // namespace internal | 2424 } // namespace internal |
2398 } // namespace v8 | 2425 } // namespace v8 |
OLD | NEW |