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/code-factory.h" | 5 #include "src/code-factory.h" |
6 #include "src/compiler/access-builder.h" | 6 #include "src/compiler/access-builder.h" |
7 #include "src/compiler/js-graph.h" | 7 #include "src/compiler/js-graph.h" |
8 #include "src/compiler/js-typed-lowering.h" | 8 #include "src/compiler/js-typed-lowering.h" |
9 #include "src/compiler/linkage.h" | 9 #include "src/compiler/linkage.h" |
10 #include "src/compiler/node-matchers.h" | 10 #include "src/compiler/node-matchers.h" |
(...skipping 962 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
973 graph()->NewNode(common()->Merge(2), check_true, check_false); | 973 graph()->NewNode(common()->Merge(2), check_true, check_false); |
974 Node* new_effect = | 974 Node* new_effect = |
975 graph()->NewNode(common()->EffectPhi(2), fast, slow, new_control); | 975 graph()->NewNode(common()->EffectPhi(2), fast, slow, new_control); |
976 Node* new_value = graph()->NewNode(common()->Phi(kMachAnyTagged, 2), fast, | 976 Node* new_value = graph()->NewNode(common()->Phi(kMachAnyTagged, 2), fast, |
977 slow, new_control); | 977 slow, new_control); |
978 ReplaceWithValue(node, new_value, new_effect, new_control); | 978 ReplaceWithValue(node, new_value, new_effect, new_control); |
979 return Changed(new_value); | 979 return Changed(new_value); |
980 } | 980 } |
981 | 981 |
982 | 982 |
| 983 Reduction JSTypedLowering::ReduceJSLoadDynamicContext(Node* node) { |
| 984 DCHECK_EQ(IrOpcode::kJSLoadDynamicContext, node->opcode()); |
| 985 DynamicContextAccess const& access = DynamicContextAccessOf(node->op()); |
| 986 ContextAccess const& context_access = access.context_access(); |
| 987 Node* const context = NodeProperties::GetContextInput(node); |
| 988 Node* const state = NodeProperties::GetFrameStateInput(node, 0); |
| 989 Node* const effect = NodeProperties::GetEffectInput(node); |
| 990 Node* const control = NodeProperties::GetControlInput(node); |
| 991 if (access.RequiresFullCheck()) return NoChange(); |
| 992 |
| 993 // Perform checks whether the fast mode applies, by looking for any extension |
| 994 // object which might shadow the optimistic declaration. |
| 995 uint32_t bitset = access.check_bitset(); |
| 996 Node* check_true = control; |
| 997 Node* check_false = graph()->NewNode(common()->Merge(0)); |
| 998 for (int depth = 0; bitset != 0; bitset >>= 1, depth++) { |
| 999 if ((bitset & 1) == 0) continue; |
| 1000 Node* load = graph()->NewNode( |
| 1001 javascript()->LoadContext(depth, Context::EXTENSION_INDEX, false), |
| 1002 context, context, effect); |
| 1003 Node* check = graph()->NewNode(simplified()->ReferenceEqual(Type::Tagged()), |
| 1004 load, jsgraph()->ZeroConstant()); |
| 1005 Node* branch = graph()->NewNode(common()->Branch(BranchHint::kTrue), check, |
| 1006 check_true); |
| 1007 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); |
| 1008 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); |
| 1009 check_false->set_op(common()->Merge(check_false->InputCount() + 1)); |
| 1010 check_false->AppendInput(graph()->zone(), if_false); |
| 1011 check_true = if_true; |
| 1012 } |
| 1013 |
| 1014 // Fast case, because variable is not shadowed. Perform context slot load. |
| 1015 Node* fast = |
| 1016 graph()->NewNode(javascript()->LoadContext(context_access.depth(), |
| 1017 context_access.index(), false), |
| 1018 context, context, effect); |
| 1019 |
| 1020 // Slow case, because variable potentially shadowed. Perform dynamic lookup. |
| 1021 uint32_t check_bitset = DynamicContextAccess::kFullCheckRequired; |
| 1022 Node* slow = |
| 1023 graph()->NewNode(javascript()->LoadDynamicContext( |
| 1024 access.name(), check_bitset, context_access.depth(), |
| 1025 context_access.index()), |
| 1026 context, context, state, effect, check_false); |
| 1027 |
| 1028 // Replace value, effect and control uses accordingly. |
| 1029 Node* new_control = |
| 1030 graph()->NewNode(common()->Merge(2), check_true, check_false); |
| 1031 Node* new_effect = |
| 1032 graph()->NewNode(common()->EffectPhi(2), fast, slow, new_control); |
| 1033 Node* new_value = graph()->NewNode(common()->Phi(kMachAnyTagged, 2), fast, |
| 1034 slow, new_control); |
| 1035 ReplaceWithValue(node, new_value, new_effect, new_control); |
| 1036 return Changed(new_value); |
| 1037 } |
| 1038 |
| 1039 |
983 Reduction JSTypedLowering::ReduceJSCreateClosure(Node* node) { | 1040 Reduction JSTypedLowering::ReduceJSCreateClosure(Node* node) { |
984 DCHECK_EQ(IrOpcode::kJSCreateClosure, node->opcode()); | 1041 DCHECK_EQ(IrOpcode::kJSCreateClosure, node->opcode()); |
985 CreateClosureParameters const& p = CreateClosureParametersOf(node->op()); | 1042 CreateClosureParameters const& p = CreateClosureParametersOf(node->op()); |
986 Handle<SharedFunctionInfo> shared = p.shared_info(); | 1043 Handle<SharedFunctionInfo> shared = p.shared_info(); |
987 | 1044 |
988 // Use the FastNewClosureStub that allocates in new space only for nested | 1045 // Use the FastNewClosureStub that allocates in new space only for nested |
989 // functions that don't need literals cloning. | 1046 // functions that don't need literals cloning. |
990 if (p.pretenure() == NOT_TENURED && shared->num_literals() == 0) { | 1047 if (p.pretenure() == NOT_TENURED && shared->num_literals() == 0) { |
991 Isolate* isolate = jsgraph()->isolate(); | 1048 Isolate* isolate = jsgraph()->isolate(); |
992 Callable callable = CodeFactory::FastNewClosure( | 1049 Callable callable = CodeFactory::FastNewClosure( |
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1482 case IrOpcode::kJSLoadProperty: | 1539 case IrOpcode::kJSLoadProperty: |
1483 return ReduceJSLoadProperty(node); | 1540 return ReduceJSLoadProperty(node); |
1484 case IrOpcode::kJSStoreProperty: | 1541 case IrOpcode::kJSStoreProperty: |
1485 return ReduceJSStoreProperty(node); | 1542 return ReduceJSStoreProperty(node); |
1486 case IrOpcode::kJSLoadContext: | 1543 case IrOpcode::kJSLoadContext: |
1487 return ReduceJSLoadContext(node); | 1544 return ReduceJSLoadContext(node); |
1488 case IrOpcode::kJSStoreContext: | 1545 case IrOpcode::kJSStoreContext: |
1489 return ReduceJSStoreContext(node); | 1546 return ReduceJSStoreContext(node); |
1490 case IrOpcode::kJSLoadDynamicGlobal: | 1547 case IrOpcode::kJSLoadDynamicGlobal: |
1491 return ReduceJSLoadDynamicGlobal(node); | 1548 return ReduceJSLoadDynamicGlobal(node); |
| 1549 case IrOpcode::kJSLoadDynamicContext: |
| 1550 return ReduceJSLoadDynamicContext(node); |
1492 case IrOpcode::kJSCreateClosure: | 1551 case IrOpcode::kJSCreateClosure: |
1493 return ReduceJSCreateClosure(node); | 1552 return ReduceJSCreateClosure(node); |
1494 case IrOpcode::kJSCreateLiteralArray: | 1553 case IrOpcode::kJSCreateLiteralArray: |
1495 return ReduceJSCreateLiteralArray(node); | 1554 return ReduceJSCreateLiteralArray(node); |
1496 case IrOpcode::kJSCreateLiteralObject: | 1555 case IrOpcode::kJSCreateLiteralObject: |
1497 return ReduceJSCreateLiteralObject(node); | 1556 return ReduceJSCreateLiteralObject(node); |
1498 case IrOpcode::kJSCreateWithContext: | 1557 case IrOpcode::kJSCreateWithContext: |
1499 return ReduceJSCreateWithContext(node); | 1558 return ReduceJSCreateWithContext(node); |
1500 case IrOpcode::kJSCreateBlockContext: | 1559 case IrOpcode::kJSCreateBlockContext: |
1501 return ReduceJSCreateBlockContext(node); | 1560 return ReduceJSCreateBlockContext(node); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1540 } | 1599 } |
1541 | 1600 |
1542 | 1601 |
1543 MachineOperatorBuilder* JSTypedLowering::machine() const { | 1602 MachineOperatorBuilder* JSTypedLowering::machine() const { |
1544 return jsgraph()->machine(); | 1603 return jsgraph()->machine(); |
1545 } | 1604 } |
1546 | 1605 |
1547 } // namespace compiler | 1606 } // namespace compiler |
1548 } // namespace internal | 1607 } // namespace internal |
1549 } // namespace v8 | 1608 } // namespace v8 |
OLD | NEW |