| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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/js-native-context-specialization.h" | 5 #include "src/compiler/js-native-context-specialization.h" |
| 6 | 6 |
| 7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
| 8 #include "src/code-factory.h" | 8 #include "src/code-factory.h" |
| 9 #include "src/compilation-dependencies.h" | 9 #include "src/compilation-dependencies.h" |
| 10 #include "src/compiler/access-builder.h" | 10 #include "src/compiler/access-builder.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 : AdvancedReducer(editor), | 62 : AdvancedReducer(editor), |
| 63 jsgraph_(jsgraph), | 63 jsgraph_(jsgraph), |
| 64 flags_(flags), | 64 flags_(flags), |
| 65 native_context_(native_context), | 65 native_context_(native_context), |
| 66 dependencies_(dependencies), | 66 dependencies_(dependencies), |
| 67 zone_(zone), | 67 zone_(zone), |
| 68 type_cache_(TypeCache::Get()) {} | 68 type_cache_(TypeCache::Get()) {} |
| 69 | 69 |
| 70 Reduction JSNativeContextSpecialization::Reduce(Node* node) { | 70 Reduction JSNativeContextSpecialization::Reduce(Node* node) { |
| 71 switch (node->opcode()) { | 71 switch (node->opcode()) { |
| 72 case IrOpcode::kJSGetSuperConstructor: |
| 73 return ReduceJSGetSuperConstructor(node); |
| 72 case IrOpcode::kJSInstanceOf: | 74 case IrOpcode::kJSInstanceOf: |
| 73 return ReduceJSInstanceOf(node); | 75 return ReduceJSInstanceOf(node); |
| 74 case IrOpcode::kJSOrdinaryHasInstance: | 76 case IrOpcode::kJSOrdinaryHasInstance: |
| 75 return ReduceJSOrdinaryHasInstance(node); | 77 return ReduceJSOrdinaryHasInstance(node); |
| 76 case IrOpcode::kJSLoadContext: | 78 case IrOpcode::kJSLoadContext: |
| 77 return ReduceJSLoadContext(node); | 79 return ReduceJSLoadContext(node); |
| 78 case IrOpcode::kJSLoadNamed: | 80 case IrOpcode::kJSLoadNamed: |
| 79 return ReduceJSLoadNamed(node); | 81 return ReduceJSLoadNamed(node); |
| 80 case IrOpcode::kJSStoreNamed: | 82 case IrOpcode::kJSStoreNamed: |
| 81 return ReduceJSStoreNamed(node); | 83 return ReduceJSStoreNamed(node); |
| 82 case IrOpcode::kJSLoadProperty: | 84 case IrOpcode::kJSLoadProperty: |
| 83 return ReduceJSLoadProperty(node); | 85 return ReduceJSLoadProperty(node); |
| 84 case IrOpcode::kJSStoreProperty: | 86 case IrOpcode::kJSStoreProperty: |
| 85 return ReduceJSStoreProperty(node); | 87 return ReduceJSStoreProperty(node); |
| 86 case IrOpcode::kJSStoreDataPropertyInLiteral: | 88 case IrOpcode::kJSStoreDataPropertyInLiteral: |
| 87 return ReduceJSStoreDataPropertyInLiteral(node); | 89 return ReduceJSStoreDataPropertyInLiteral(node); |
| 88 default: | 90 default: |
| 89 break; | 91 break; |
| 90 } | 92 } |
| 91 return NoChange(); | 93 return NoChange(); |
| 92 } | 94 } |
| 93 | 95 |
| 96 Reduction JSNativeContextSpecialization::ReduceJSGetSuperConstructor( |
| 97 Node* node) { |
| 98 DCHECK_EQ(IrOpcode::kJSGetSuperConstructor, node->opcode()); |
| 99 Node* constructor = NodeProperties::GetValueInput(node, 0); |
| 100 |
| 101 // If deoptimization is disabled, we cannot optimize. |
| 102 if (!(flags() & kDeoptimizationEnabled)) return NoChange(); |
| 103 |
| 104 // Check if the input is a known JSFunction. |
| 105 HeapObjectMatcher m(constructor); |
| 106 if (!m.HasValue()) return NoChange(); |
| 107 Handle<JSFunction> function = Handle<JSFunction>::cast(m.Value()); |
| 108 Handle<Map> function_map(function->map(), isolate()); |
| 109 Handle<Object> function_prototype(function_map->prototype(), isolate()); |
| 110 |
| 111 // We can constant-fold the super constructor access if the |
| 112 // {function}s map is stable, i.e. we can use a code dependency |
| 113 // to guard against [[Prototype]] changes of {function}. |
| 114 if (function_map->is_stable()) { |
| 115 Node* value = jsgraph()->Constant(function_prototype); |
| 116 dependencies()->AssumeMapStable(function_map); |
| 117 if (function_prototype->IsConstructor()) { |
| 118 ReplaceWithValue(node, value); |
| 119 return Replace(value); |
| 120 } else { |
| 121 node->InsertInput(graph()->zone(), 0, value); |
| 122 NodeProperties::ChangeOp( |
| 123 node, javascript()->CallRuntime(Runtime::kThrowNotSuperConstructor)); |
| 124 return Changed(node); |
| 125 } |
| 126 } |
| 127 |
| 128 return NoChange(); |
| 129 } |
| 130 |
| 94 Reduction JSNativeContextSpecialization::ReduceJSInstanceOf(Node* node) { | 131 Reduction JSNativeContextSpecialization::ReduceJSInstanceOf(Node* node) { |
| 95 DCHECK_EQ(IrOpcode::kJSInstanceOf, node->opcode()); | 132 DCHECK_EQ(IrOpcode::kJSInstanceOf, node->opcode()); |
| 96 Node* object = NodeProperties::GetValueInput(node, 0); | 133 Node* object = NodeProperties::GetValueInput(node, 0); |
| 97 Node* constructor = NodeProperties::GetValueInput(node, 1); | 134 Node* constructor = NodeProperties::GetValueInput(node, 1); |
| 98 Node* context = NodeProperties::GetContextInput(node); | 135 Node* context = NodeProperties::GetContextInput(node); |
| 99 Node* effect = NodeProperties::GetEffectInput(node); | 136 Node* effect = NodeProperties::GetEffectInput(node); |
| 100 Node* control = NodeProperties::GetControlInput(node); | 137 Node* control = NodeProperties::GetControlInput(node); |
| 101 | 138 |
| 102 // If deoptimization is disabled, we cannot optimize. | 139 // If deoptimization is disabled, we cannot optimize. |
| 103 if (!(flags() & kDeoptimizationEnabled)) return NoChange(); | 140 if (!(flags() & kDeoptimizationEnabled)) return NoChange(); |
| (...skipping 1816 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1920 return jsgraph()->javascript(); | 1957 return jsgraph()->javascript(); |
| 1921 } | 1958 } |
| 1922 | 1959 |
| 1923 SimplifiedOperatorBuilder* JSNativeContextSpecialization::simplified() const { | 1960 SimplifiedOperatorBuilder* JSNativeContextSpecialization::simplified() const { |
| 1924 return jsgraph()->simplified(); | 1961 return jsgraph()->simplified(); |
| 1925 } | 1962 } |
| 1926 | 1963 |
| 1927 } // namespace compiler | 1964 } // namespace compiler |
| 1928 } // namespace internal | 1965 } // namespace internal |
| 1929 } // namespace v8 | 1966 } // namespace v8 |
| OLD | NEW |