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/base/flags.h" | 5 #include "src/base/flags.h" |
6 #include "src/bootstrapper.h" | 6 #include "src/bootstrapper.h" |
7 #include "src/compiler/graph-reducer.h" | 7 #include "src/compiler/graph-reducer.h" |
8 #include "src/compiler/js-operator.h" | 8 #include "src/compiler/js-operator.h" |
9 #include "src/compiler/node.h" | 9 #include "src/compiler/node.h" |
10 #include "src/compiler/node-properties.h" | 10 #include "src/compiler/node-properties.h" |
(...skipping 1426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1437 | 1437 |
1438 Bounds Typer::Visitor::TypeJSInstanceOf(Node* node) { | 1438 Bounds Typer::Visitor::TypeJSInstanceOf(Node* node) { |
1439 return Bounds(Type::None(zone()), Type::Boolean(zone())); | 1439 return Bounds(Type::None(zone()), Type::Boolean(zone())); |
1440 } | 1440 } |
1441 | 1441 |
1442 | 1442 |
1443 // JS context operators. | 1443 // JS context operators. |
1444 | 1444 |
1445 | 1445 |
1446 Bounds Typer::Visitor::TypeJSLoadContext(Node* node) { | 1446 Bounds Typer::Visitor::TypeJSLoadContext(Node* node) { |
| 1447 ContextAccess access = OpParameter<ContextAccess>(node); |
1447 Bounds outer = Operand(node, 0); | 1448 Bounds outer = Operand(node, 0); |
1448 Type* context_type = outer.upper; | 1449 Type* context_type = outer.upper; |
| 1450 Type* upper = (access.index() == Context::GLOBAL_OBJECT_INDEX) |
| 1451 ? Type::GlobalObject() |
| 1452 : Type::Any(); |
1449 if (context_type->Is(Type::None())) { | 1453 if (context_type->Is(Type::None())) { |
1450 // Upper bound of context is not yet known. | 1454 // Upper bound of context is not yet known. |
1451 return Bounds(Type::None(), Type::Any()); | 1455 return Bounds(Type::None(), upper); |
1452 } | 1456 } |
1453 | 1457 |
1454 DCHECK(context_type->Maybe(Type::Internal())); | 1458 DCHECK(context_type->Maybe(Type::Internal())); |
1455 // TODO(rossberg): More precisely, instead of the above assertion, we should | 1459 // TODO(rossberg): More precisely, instead of the above assertion, we should |
1456 // back-propagate the constraint that it has to be a subtype of Internal. | 1460 // back-propagate the constraint that it has to be a subtype of Internal. |
1457 | 1461 |
1458 ContextAccess access = OpParameter<ContextAccess>(node); | |
1459 MaybeHandle<Context> context; | 1462 MaybeHandle<Context> context; |
1460 if (context_type->IsConstant()) { | 1463 if (context_type->IsConstant()) { |
1461 context = Handle<Context>::cast(context_type->AsConstant()->Value()); | 1464 context = Handle<Context>::cast(context_type->AsConstant()->Value()); |
1462 } | 1465 } |
1463 // Walk context chain (as far as known), mirroring dynamic lookup. | 1466 // Walk context chain (as far as known), mirroring dynamic lookup. |
1464 // Since contexts are mutable, the information is only useful as a lower | 1467 // Since contexts are mutable, the information is only useful as a lower |
1465 // bound. | 1468 // bound. |
1466 // TODO(rossberg): Could use scope info to fix upper bounds for constant | |
1467 // bindings if we know that this code is never shared. | |
1468 for (size_t i = access.depth(); i > 0; --i) { | 1469 for (size_t i = access.depth(); i > 0; --i) { |
1469 if (context_type->IsContext()) { | 1470 if (context_type->IsContext()) { |
1470 context_type = context_type->AsContext()->Outer(); | 1471 context_type = context_type->AsContext()->Outer(); |
1471 if (context_type->IsConstant()) { | 1472 if (context_type->IsConstant()) { |
1472 context = Handle<Context>::cast(context_type->AsConstant()->Value()); | 1473 context = Handle<Context>::cast(context_type->AsConstant()->Value()); |
1473 } | 1474 } |
1474 } else if (!context.is_null()) { | 1475 } else if (!context.is_null()) { |
1475 context = handle(context.ToHandleChecked()->previous(), isolate()); | 1476 context = handle(context.ToHandleChecked()->previous(), isolate()); |
1476 } | 1477 } |
1477 } | 1478 } |
1478 if (context.is_null()) { | 1479 Type* lower = Type::None(); |
1479 return Bounds::Unbounded(zone()); | 1480 if (!context.is_null()) { |
1480 } else { | 1481 lower = TypeConstant( |
1481 Handle<Object> value = | |
1482 handle(context.ToHandleChecked()->get(static_cast<int>(access.index())), | 1482 handle(context.ToHandleChecked()->get(static_cast<int>(access.index())), |
1483 isolate()); | 1483 isolate())); |
1484 Type* lower = TypeConstant(value); | |
1485 return Bounds(lower, Type::Any()); | |
1486 } | 1484 } |
| 1485 return Bounds(lower, upper); |
1487 } | 1486 } |
1488 | 1487 |
1489 | 1488 |
1490 Bounds Typer::Visitor::TypeJSStoreContext(Node* node) { | 1489 Bounds Typer::Visitor::TypeJSStoreContext(Node* node) { |
1491 UNREACHABLE(); | 1490 UNREACHABLE(); |
1492 return Bounds(); | 1491 return Bounds(); |
1493 } | 1492 } |
1494 | 1493 |
1495 | 1494 |
1496 Bounds Typer::Visitor::WrapContextBoundsForInput(Node* node) { | 1495 Bounds Typer::Visitor::WrapContextBoundsForInput(Node* node) { |
(...skipping 850 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2347 TYPED_ARRAYS(TYPED_ARRAY_CASE) | 2346 TYPED_ARRAYS(TYPED_ARRAY_CASE) |
2348 #undef TYPED_ARRAY_CASE | 2347 #undef TYPED_ARRAY_CASE |
2349 } | 2348 } |
2350 } | 2349 } |
2351 return Type::Constant(value, zone()); | 2350 return Type::Constant(value, zone()); |
2352 } | 2351 } |
2353 | 2352 |
2354 } // namespace compiler | 2353 } // namespace compiler |
2355 } // namespace internal | 2354 } // namespace internal |
2356 } // namespace v8 | 2355 } // namespace v8 |
OLD | NEW |