| 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*); | |
| 299 | 298 |
| 300 Reduction UpdateType(Node* node, Type* current) { | 299 Reduction UpdateType(Node* node, Type* current) { |
| 301 if (NodeProperties::IsTyped(node)) { | 300 if (NodeProperties::IsTyped(node)) { |
| 302 // Widen the type of a previously typed node. | 301 // Widen the type of a previously typed node. |
| 303 Type* previous = NodeProperties::GetType(node); | 302 Type* previous = NodeProperties::GetType(node); |
| 304 if (node->opcode() == IrOpcode::kPhi || | 303 if (node->opcode() == IrOpcode::kPhi || |
| 305 node->opcode() == IrOpcode::kInductionVariablePhi) { | 304 node->opcode() == IrOpcode::kInductionVariablePhi) { |
| 306 // Speed up termination in the presence of range types: | 305 // Speed up termination in the presence of range types: |
| 307 current = Weaken(node, current, previous); | 306 current = Weaken(node, current, previous); |
| 308 } | 307 } |
| (...skipping 1050 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1359 case kStringCharCodeAt: | 1358 case kStringCharCodeAt: |
| 1360 return Type::Union(Type::Range(0, kMaxUInt16, t->zone()), Type::NaN(), | 1359 return Type::Union(Type::Range(0, kMaxUInt16, t->zone()), Type::NaN(), |
| 1361 t->zone()); | 1360 t->zone()); |
| 1362 case kStringCharAt: | 1361 case kStringCharAt: |
| 1363 case kStringConcat: | 1362 case kStringConcat: |
| 1364 case kStringFromCharCode: | 1363 case kStringFromCharCode: |
| 1365 case kStringSubstr: | 1364 case kStringSubstr: |
| 1366 case kStringToLowerCase: | 1365 case kStringToLowerCase: |
| 1367 case kStringToUpperCase: | 1366 case kStringToUpperCase: |
| 1368 return Type::String(); | 1367 return Type::String(); |
| 1369 | |
| 1370 case kStringIteratorNext: | |
| 1371 return Type::OtherObject(); | |
| 1372 | |
| 1373 // Array functions. | 1368 // Array functions. |
| 1374 case kArrayIndexOf: | 1369 case kArrayIndexOf: |
| 1375 case kArrayLastIndexOf: | 1370 case kArrayLastIndexOf: |
| 1376 return Type::Range(-1, kMaxSafeInteger, t->zone()); | 1371 return Type::Range(-1, kMaxSafeInteger, t->zone()); |
| 1377 // Object functions. | 1372 // Object functions. |
| 1378 case kObjectHasOwnProperty: | 1373 case kObjectHasOwnProperty: |
| 1379 return Type::Boolean(); | 1374 return Type::Boolean(); |
| 1380 // Global functions. | 1375 // Global functions. |
| 1381 case kGlobalDecodeURI: | 1376 case kGlobalDecodeURI: |
| 1382 case kGlobalDecodeURIComponent: | 1377 case kGlobalDecodeURIComponent: |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1549 double min = type->Min(); | 1544 double min = type->Min(); |
| 1550 double max = type->Max(); | 1545 double max = type->Max(); |
| 1551 if (min == max) { | 1546 if (min == max) { |
| 1552 uint32_t code = static_cast<uint32_t>(min) & String::kMaxUtf16CodeUnitU; | 1547 uint32_t code = static_cast<uint32_t>(min) & String::kMaxUtf16CodeUnitU; |
| 1553 Handle<String> string = f->LookupSingleCharacterStringFromCode(code); | 1548 Handle<String> string = f->LookupSingleCharacterStringFromCode(code); |
| 1554 return Type::Constant(string, t->zone()); | 1549 return Type::Constant(string, t->zone()); |
| 1555 } | 1550 } |
| 1556 return Type::String(); | 1551 return Type::String(); |
| 1557 } | 1552 } |
| 1558 | 1553 |
| 1559 Type* Typer::Visitor::StringFromCodePointTyper(Type* type, Typer* t) { | |
| 1560 type = NumberToUint32(ToNumber(type, t), t); | |
| 1561 Factory* f = t->isolate()->factory(); | |
| 1562 double min = type->Min(); | |
| 1563 double max = type->Max(); | |
| 1564 if (min == max) { | |
| 1565 uint32_t code = static_cast<uint32_t>(min) & String::kMaxUtf16CodeUnitU; | |
| 1566 Handle<String> string = f->LookupSingleCharacterStringFromCode(code); | |
| 1567 return Type::Constant(string, t->zone()); | |
| 1568 } | |
| 1569 return Type::String(); | |
| 1570 } | |
| 1571 | |
| 1572 Type* Typer::Visitor::TypeStringCharCodeAt(Node* node) { | 1554 Type* Typer::Visitor::TypeStringCharCodeAt(Node* node) { |
| 1573 // TODO(bmeurer): We could do better here based on inputs. | 1555 // TODO(bmeurer): We could do better here based on inputs. |
| 1574 return Type::Range(0, kMaxUInt16, zone()); | 1556 return Type::Range(0, kMaxUInt16, zone()); |
| 1575 } | 1557 } |
| 1576 | 1558 |
| 1577 Type* Typer::Visitor::TypeStringFromCharCode(Node* node) { | 1559 Type* Typer::Visitor::TypeStringFromCharCode(Node* node) { |
| 1578 return TypeUnaryOp(node, StringFromCharCodeTyper); | 1560 return TypeUnaryOp(node, StringFromCharCodeTyper); |
| 1579 } | 1561 } |
| 1580 | 1562 |
| 1581 Type* Typer::Visitor::TypeStringFromCodePoint(Node* node) { | |
| 1582 return TypeUnaryOp(node, StringFromCodePointTyper); | |
| 1583 } | |
| 1584 | |
| 1585 Type* Typer::Visitor::TypeCheckBounds(Node* node) { | 1563 Type* Typer::Visitor::TypeCheckBounds(Node* node) { |
| 1586 Type* index = Operand(node, 0); | 1564 Type* index = Operand(node, 0); |
| 1587 Type* length = Operand(node, 1); | 1565 Type* length = Operand(node, 1); |
| 1588 index = Type::Intersect(index, Type::Integral32(), zone()); | 1566 index = Type::Intersect(index, Type::Integral32(), zone()); |
| 1589 if (!index->IsInhabited() || !length->IsInhabited()) return Type::None(); | 1567 if (!index->IsInhabited() || !length->IsInhabited()) return Type::None(); |
| 1590 double min = std::max(index->Min(), 0.0); | 1568 double min = std::max(index->Min(), 0.0); |
| 1591 double max = std::min(index->Max(), length->Max() - 1); | 1569 double max = std::min(index->Max(), length->Max() - 1); |
| 1592 if (max < min) return Type::None(); | 1570 if (max < min) return Type::None(); |
| 1593 return Type::Range(min, max, zone()); | 1571 return Type::Range(min, max, zone()); |
| 1594 } | 1572 } |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1738 Type* Typer::Visitor::TypeConstant(Handle<Object> value) { | 1716 Type* Typer::Visitor::TypeConstant(Handle<Object> value) { |
| 1739 if (Type::IsInteger(*value)) { | 1717 if (Type::IsInteger(*value)) { |
| 1740 return Type::Range(value->Number(), value->Number(), zone()); | 1718 return Type::Range(value->Number(), value->Number(), zone()); |
| 1741 } | 1719 } |
| 1742 return Type::Constant(value, zone()); | 1720 return Type::Constant(value, zone()); |
| 1743 } | 1721 } |
| 1744 | 1722 |
| 1745 } // namespace compiler | 1723 } // namespace compiler |
| 1746 } // namespace internal | 1724 } // namespace internal |
| 1747 } // namespace v8 | 1725 } // namespace v8 |
| OLD | NEW |