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 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 static Type* Rangify(Type*, Typer*); | 233 static Type* Rangify(Type*, Typer*); |
234 | 234 |
235 static Type* ToPrimitive(Type*, Typer*); | 235 static Type* ToPrimitive(Type*, Typer*); |
236 static Type* ToBoolean(Type*, Typer*); | 236 static Type* ToBoolean(Type*, Typer*); |
237 static Type* ToInteger(Type*, Typer*); | 237 static Type* ToInteger(Type*, Typer*); |
238 static Type* ToLength(Type*, Typer*); | 238 static Type* ToLength(Type*, Typer*); |
239 static Type* ToName(Type*, Typer*); | 239 static Type* ToName(Type*, Typer*); |
240 static Type* ToNumber(Type*, Typer*); | 240 static Type* ToNumber(Type*, Typer*); |
241 static Type* ToObject(Type*, Typer*); | 241 static Type* ToObject(Type*, Typer*); |
242 static Type* ToString(Type*, Typer*); | 242 static Type* ToString(Type*, Typer*); |
| 243 static Type* NumberCeil(Type*, Typer*); |
243 static Type* NumberFloor(Type*, Typer*); | 244 static Type* NumberFloor(Type*, Typer*); |
| 245 static Type* NumberRound(Type*, Typer*); |
| 246 static Type* NumberTrunc(Type*, Typer*); |
244 static Type* NumberToInt32(Type*, Typer*); | 247 static Type* NumberToInt32(Type*, Typer*); |
245 static Type* NumberToUint32(Type*, Typer*); | 248 static Type* NumberToUint32(Type*, Typer*); |
246 | 249 |
247 static Type* ObjectIsNumber(Type*, Typer*); | 250 static Type* ObjectIsNumber(Type*, Typer*); |
248 static Type* ObjectIsReceiver(Type*, Typer*); | 251 static Type* ObjectIsReceiver(Type*, Typer*); |
249 static Type* ObjectIsSmi(Type*, Typer*); | 252 static Type* ObjectIsSmi(Type*, Typer*); |
250 static Type* ObjectIsUndetectable(Type*, Typer*); | 253 static Type* ObjectIsUndetectable(Type*, Typer*); |
251 | 254 |
252 static Type* JSAddRanger(RangeType*, RangeType*, Typer*); | 255 static Type* JSAddRanger(RangeType*, RangeType*, Typer*); |
253 static Type* JSSubtractRanger(RangeType*, RangeType*, Typer*); | 256 static Type* JSSubtractRanger(RangeType*, RangeType*, Typer*); |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 | 485 |
483 // static | 486 // static |
484 Type* Typer::Visitor::ToString(Type* type, Typer* t) { | 487 Type* Typer::Visitor::ToString(Type* type, Typer* t) { |
485 // ES6 section 7.1.12 ToString ( argument ) | 488 // ES6 section 7.1.12 ToString ( argument ) |
486 type = ToPrimitive(type, t); | 489 type = ToPrimitive(type, t); |
487 if (type->Is(Type::String())) return type; | 490 if (type->Is(Type::String())) return type; |
488 return Type::String(); | 491 return Type::String(); |
489 } | 492 } |
490 | 493 |
491 // static | 494 // static |
| 495 Type* Typer::Visitor::NumberCeil(Type* type, Typer* t) { |
| 496 DCHECK(type->Is(Type::Number())); |
| 497 if (type->Is(t->cache_.kIntegerOrMinusZeroOrNaN)) return type; |
| 498 // TODO(bmeurer): We could infer a more precise type here. |
| 499 return t->cache_.kIntegerOrMinusZeroOrNaN; |
| 500 } |
| 501 |
| 502 // static |
492 Type* Typer::Visitor::NumberFloor(Type* type, Typer* t) { | 503 Type* Typer::Visitor::NumberFloor(Type* type, Typer* t) { |
493 DCHECK(type->Is(Type::Number())); | 504 DCHECK(type->Is(Type::Number())); |
494 if (type->Is(t->cache_.kIntegerOrMinusZeroOrNaN)) return type; | 505 if (type->Is(t->cache_.kIntegerOrMinusZeroOrNaN)) return type; |
| 506 // TODO(bmeurer): We could infer a more precise type here. |
495 return t->cache_.kIntegerOrMinusZeroOrNaN; | 507 return t->cache_.kIntegerOrMinusZeroOrNaN; |
496 } | 508 } |
497 | 509 |
| 510 // static |
| 511 Type* Typer::Visitor::NumberRound(Type* type, Typer* t) { |
| 512 DCHECK(type->Is(Type::Number())); |
| 513 if (type->Is(t->cache_.kIntegerOrMinusZeroOrNaN)) return type; |
| 514 // TODO(bmeurer): We could infer a more precise type here. |
| 515 return t->cache_.kIntegerOrMinusZeroOrNaN; |
| 516 } |
| 517 |
| 518 // static |
| 519 Type* Typer::Visitor::NumberTrunc(Type* type, Typer* t) { |
| 520 DCHECK(type->Is(Type::Number())); |
| 521 if (type->Is(t->cache_.kIntegerOrMinusZeroOrNaN)) return type; |
| 522 // TODO(bmeurer): We could infer a more precise type here. |
| 523 return t->cache_.kIntegerOrMinusZeroOrNaN; |
| 524 } |
| 525 |
498 Type* Typer::Visitor::NumberToInt32(Type* type, Typer* t) { | 526 Type* Typer::Visitor::NumberToInt32(Type* type, Typer* t) { |
499 // TODO(neis): DCHECK(type->Is(Type::Number())); | 527 // TODO(neis): DCHECK(type->Is(Type::Number())); |
500 if (type->Is(Type::Signed32())) return type; | 528 if (type->Is(Type::Signed32())) return type; |
501 if (type->Is(t->cache_.kZeroish)) return t->cache_.kSingletonZero; | 529 if (type->Is(t->cache_.kZeroish)) return t->cache_.kSingletonZero; |
502 if (type->Is(t->signed32ish_)) { | 530 if (type->Is(t->signed32ish_)) { |
503 return Type::Intersect( | 531 return Type::Intersect( |
504 Type::Union(type, t->cache_.kSingletonZero, t->zone()), | 532 Type::Union(type, t->cache_.kSingletonZero, t->zone()), |
505 Type::Signed32(), t->zone()); | 533 Type::Signed32(), t->zone()); |
506 } | 534 } |
507 return Type::Signed32(); | 535 return Type::Signed32(); |
(...skipping 1006 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1514 return fun->AsFunction()->Result(); | 1542 return fun->AsFunction()->Result(); |
1515 } | 1543 } |
1516 if (fun->IsConstant() && fun->AsConstant()->Value()->IsJSFunction()) { | 1544 if (fun->IsConstant() && fun->AsConstant()->Value()->IsJSFunction()) { |
1517 Handle<JSFunction> function = | 1545 Handle<JSFunction> function = |
1518 Handle<JSFunction>::cast(fun->AsConstant()->Value()); | 1546 Handle<JSFunction>::cast(fun->AsConstant()->Value()); |
1519 if (function->shared()->HasBuiltinFunctionId()) { | 1547 if (function->shared()->HasBuiltinFunctionId()) { |
1520 switch (function->shared()->builtin_function_id()) { | 1548 switch (function->shared()->builtin_function_id()) { |
1521 case kMathRandom: | 1549 case kMathRandom: |
1522 return Type::OrderedNumber(); | 1550 return Type::OrderedNumber(); |
1523 case kMathFloor: | 1551 case kMathFloor: |
| 1552 case kMathCeil: |
1524 case kMathRound: | 1553 case kMathRound: |
1525 case kMathCeil: | 1554 case kMathTrunc: |
1526 return t->cache_.kIntegerOrMinusZeroOrNaN; | 1555 return t->cache_.kIntegerOrMinusZeroOrNaN; |
1527 // Unary math functions. | 1556 // Unary math functions. |
1528 case kMathAbs: | 1557 case kMathAbs: |
1529 case kMathLog: | 1558 case kMathLog: |
1530 case kMathExp: | 1559 case kMathExp: |
1531 case kMathSqrt: | 1560 case kMathSqrt: |
1532 case kMathCos: | 1561 case kMathCos: |
1533 case kMathSin: | 1562 case kMathSin: |
1534 case kMathTan: | 1563 case kMathTan: |
1535 case kMathAcos: | 1564 case kMathAcos: |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1715 | 1744 |
1716 Type* Typer::Visitor::TypeNumberShiftRight(Node* node) { | 1745 Type* Typer::Visitor::TypeNumberShiftRight(Node* node) { |
1717 return Type::Signed32(); | 1746 return Type::Signed32(); |
1718 } | 1747 } |
1719 | 1748 |
1720 | 1749 |
1721 Type* Typer::Visitor::TypeNumberShiftRightLogical(Node* node) { | 1750 Type* Typer::Visitor::TypeNumberShiftRightLogical(Node* node) { |
1722 return Type::Unsigned32(); | 1751 return Type::Unsigned32(); |
1723 } | 1752 } |
1724 | 1753 |
| 1754 Type* Typer::Visitor::TypeNumberCeil(Node* node) { |
| 1755 return TypeUnaryOp(node, NumberCeil); |
| 1756 } |
| 1757 |
1725 Type* Typer::Visitor::TypeNumberFloor(Node* node) { | 1758 Type* Typer::Visitor::TypeNumberFloor(Node* node) { |
1726 return TypeUnaryOp(node, NumberFloor); | 1759 return TypeUnaryOp(node, NumberFloor); |
1727 } | 1760 } |
1728 | 1761 |
| 1762 Type* Typer::Visitor::TypeNumberRound(Node* node) { |
| 1763 return TypeUnaryOp(node, NumberRound); |
| 1764 } |
| 1765 |
| 1766 Type* Typer::Visitor::TypeNumberTrunc(Node* node) { |
| 1767 return TypeUnaryOp(node, NumberTrunc); |
| 1768 } |
| 1769 |
1729 Type* Typer::Visitor::TypeNumberToInt32(Node* node) { | 1770 Type* Typer::Visitor::TypeNumberToInt32(Node* node) { |
1730 return TypeUnaryOp(node, NumberToInt32); | 1771 return TypeUnaryOp(node, NumberToInt32); |
1731 } | 1772 } |
1732 | 1773 |
1733 | 1774 |
1734 Type* Typer::Visitor::TypeNumberToUint32(Node* node) { | 1775 Type* Typer::Visitor::TypeNumberToUint32(Node* node) { |
1735 return TypeUnaryOp(node, NumberToUint32); | 1776 return TypeUnaryOp(node, NumberToUint32); |
1736 } | 1777 } |
1737 | 1778 |
1738 | 1779 |
(...skipping 738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2477 } | 2518 } |
2478 if (Type::IsInteger(*value)) { | 2519 if (Type::IsInteger(*value)) { |
2479 return Type::Range(value->Number(), value->Number(), zone()); | 2520 return Type::Range(value->Number(), value->Number(), zone()); |
2480 } | 2521 } |
2481 return Type::Constant(value, zone()); | 2522 return Type::Constant(value, zone()); |
2482 } | 2523 } |
2483 | 2524 |
2484 } // namespace compiler | 2525 } // namespace compiler |
2485 } // namespace internal | 2526 } // namespace internal |
2486 } // namespace v8 | 2527 } // namespace v8 |
OLD | NEW |