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 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 | 288 |
289 #define DECLARE_METHOD(x) static Type* x##Typer(Type*, Type*, Typer*); | 289 #define DECLARE_METHOD(x) static Type* x##Typer(Type*, Type*, Typer*); |
290 JS_SIMPLE_BINOP_LIST(DECLARE_METHOD) | 290 JS_SIMPLE_BINOP_LIST(DECLARE_METHOD) |
291 #undef DECLARE_METHOD | 291 #undef DECLARE_METHOD |
292 | 292 |
293 static Type* JSTypeOfTyper(Type*, Typer*); | 293 static Type* JSTypeOfTyper(Type*, Typer*); |
294 static Type* JSCallFunctionTyper(Type*, Typer*); | 294 static Type* JSCallFunctionTyper(Type*, Typer*); |
295 | 295 |
296 static Type* ReferenceEqualTyper(Type*, Type*, Typer*); | 296 static Type* ReferenceEqualTyper(Type*, Type*, Typer*); |
297 static Type* StringFromCharCodeTyper(Type*, Typer*); | 297 static Type* StringFromCharCodeTyper(Type*, Typer*); |
| 298 static Type* StringFromCodePointTyper(Type*, Typer*); |
298 | 299 |
299 Reduction UpdateType(Node* node, Type* current) { | 300 Reduction UpdateType(Node* node, Type* current) { |
300 if (NodeProperties::IsTyped(node)) { | 301 if (NodeProperties::IsTyped(node)) { |
301 // Widen the type of a previously typed node. | 302 // Widen the type of a previously typed node. |
302 Type* previous = NodeProperties::GetType(node); | 303 Type* previous = NodeProperties::GetType(node); |
303 if (node->opcode() == IrOpcode::kPhi || | 304 if (node->opcode() == IrOpcode::kPhi || |
304 node->opcode() == IrOpcode::kInductionVariablePhi) { | 305 node->opcode() == IrOpcode::kInductionVariablePhi) { |
305 // Speed up termination in the presence of range types: | 306 // Speed up termination in the presence of range types: |
306 current = Weaken(node, current, previous); | 307 current = Weaken(node, current, previous); |
307 } | 308 } |
(...skipping 1236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1544 double min = type->Min(); | 1545 double min = type->Min(); |
1545 double max = type->Max(); | 1546 double max = type->Max(); |
1546 if (min == max) { | 1547 if (min == max) { |
1547 uint32_t code = static_cast<uint32_t>(min) & String::kMaxUtf16CodeUnitU; | 1548 uint32_t code = static_cast<uint32_t>(min) & String::kMaxUtf16CodeUnitU; |
1548 Handle<String> string = f->LookupSingleCharacterStringFromCode(code); | 1549 Handle<String> string = f->LookupSingleCharacterStringFromCode(code); |
1549 return Type::Constant(string, t->zone()); | 1550 return Type::Constant(string, t->zone()); |
1550 } | 1551 } |
1551 return Type::String(); | 1552 return Type::String(); |
1552 } | 1553 } |
1553 | 1554 |
| 1555 Type* Typer::Visitor::StringFromCodePointTyper(Type* type, Typer* t) { |
| 1556 type = NumberToUint32(ToNumber(type, t), t); |
| 1557 Factory* f = t->isolate()->factory(); |
| 1558 double min = type->Min(); |
| 1559 double max = type->Max(); |
| 1560 if (min == max) { |
| 1561 uint32_t code = static_cast<uint32_t>(min) & String::kMaxUtf16CodeUnitU; |
| 1562 Handle<String> string = f->LookupSingleCharacterStringFromCode(code); |
| 1563 return Type::Constant(string, t->zone()); |
| 1564 } |
| 1565 return Type::String(); |
| 1566 } |
| 1567 |
1554 Type* Typer::Visitor::TypeStringCharCodeAt(Node* node) { | 1568 Type* Typer::Visitor::TypeStringCharCodeAt(Node* node) { |
1555 // TODO(bmeurer): We could do better here based on inputs. | 1569 // TODO(bmeurer): We could do better here based on inputs. |
1556 return Type::Range(0, kMaxUInt16, zone()); | 1570 return Type::Range(0, kMaxUInt16, zone()); |
1557 } | 1571 } |
1558 | 1572 |
1559 Type* Typer::Visitor::TypeStringFromCharCode(Node* node) { | 1573 Type* Typer::Visitor::TypeStringFromCharCode(Node* node) { |
1560 return TypeUnaryOp(node, StringFromCharCodeTyper); | 1574 return TypeUnaryOp(node, StringFromCharCodeTyper); |
1561 } | 1575 } |
1562 | 1576 |
| 1577 Type* Typer::Visitor::TypeStringFromCodePoint(Node* node) { |
| 1578 return TypeUnaryOp(node, StringFromCodePointTyper); |
| 1579 } |
| 1580 |
1563 Type* Typer::Visitor::TypeCheckBounds(Node* node) { | 1581 Type* Typer::Visitor::TypeCheckBounds(Node* node) { |
1564 Type* index = Operand(node, 0); | 1582 Type* index = Operand(node, 0); |
1565 Type* length = Operand(node, 1); | 1583 Type* length = Operand(node, 1); |
1566 index = Type::Intersect(index, Type::Integral32(), zone()); | 1584 index = Type::Intersect(index, Type::Integral32(), zone()); |
1567 if (!index->IsInhabited() || !length->IsInhabited()) return Type::None(); | 1585 if (!index->IsInhabited() || !length->IsInhabited()) return Type::None(); |
1568 double min = std::max(index->Min(), 0.0); | 1586 double min = std::max(index->Min(), 0.0); |
1569 double max = std::min(index->Max(), length->Max() - 1); | 1587 double max = std::min(index->Max(), length->Max() - 1); |
1570 if (max < min) return Type::None(); | 1588 if (max < min) return Type::None(); |
1571 return Type::Range(min, max, zone()); | 1589 return Type::Range(min, max, zone()); |
1572 } | 1590 } |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1716 Type* Typer::Visitor::TypeConstant(Handle<Object> value) { | 1734 Type* Typer::Visitor::TypeConstant(Handle<Object> value) { |
1717 if (Type::IsInteger(*value)) { | 1735 if (Type::IsInteger(*value)) { |
1718 return Type::Range(value->Number(), value->Number(), zone()); | 1736 return Type::Range(value->Number(), value->Number(), zone()); |
1719 } | 1737 } |
1720 return Type::Constant(value, zone()); | 1738 return Type::Constant(value, zone()); |
1721 } | 1739 } |
1722 | 1740 |
1723 } // namespace compiler | 1741 } // namespace compiler |
1724 } // namespace internal | 1742 } // namespace internal |
1725 } // namespace v8 | 1743 } // namespace v8 |
OLD | NEW |