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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 flags_(flags), | 70 flags_(flags), |
71 global_object_(native_context->global_object()), | 71 global_object_(native_context->global_object()), |
72 global_proxy_(JSGlobalProxy::cast(native_context->global_proxy())), | 72 global_proxy_(JSGlobalProxy::cast(native_context->global_proxy())), |
73 native_context_(native_context), | 73 native_context_(native_context), |
74 dependencies_(dependencies), | 74 dependencies_(dependencies), |
75 zone_(zone), | 75 zone_(zone), |
76 type_cache_(TypeCache::Get()) {} | 76 type_cache_(TypeCache::Get()) {} |
77 | 77 |
78 Reduction JSNativeContextSpecialization::Reduce(Node* node) { | 78 Reduction JSNativeContextSpecialization::Reduce(Node* node) { |
79 switch (node->opcode()) { | 79 switch (node->opcode()) { |
| 80 case IrOpcode::kJSAdd: |
| 81 return ReduceJSAdd(node); |
80 case IrOpcode::kJSGetSuperConstructor: | 82 case IrOpcode::kJSGetSuperConstructor: |
81 return ReduceJSGetSuperConstructor(node); | 83 return ReduceJSGetSuperConstructor(node); |
82 case IrOpcode::kJSInstanceOf: | 84 case IrOpcode::kJSInstanceOf: |
83 return ReduceJSInstanceOf(node); | 85 return ReduceJSInstanceOf(node); |
84 case IrOpcode::kJSOrdinaryHasInstance: | 86 case IrOpcode::kJSOrdinaryHasInstance: |
85 return ReduceJSOrdinaryHasInstance(node); | 87 return ReduceJSOrdinaryHasInstance(node); |
86 case IrOpcode::kJSLoadContext: | 88 case IrOpcode::kJSLoadContext: |
87 return ReduceJSLoadContext(node); | 89 return ReduceJSLoadContext(node); |
88 case IrOpcode::kJSLoadGlobal: | 90 case IrOpcode::kJSLoadGlobal: |
89 return ReduceJSLoadGlobal(node); | 91 return ReduceJSLoadGlobal(node); |
(...skipping 10 matching lines...) Expand all Loading... |
100 case IrOpcode::kJSStoreNamedOwn: | 102 case IrOpcode::kJSStoreNamedOwn: |
101 return ReduceJSStoreNamedOwn(node); | 103 return ReduceJSStoreNamedOwn(node); |
102 case IrOpcode::kJSStoreDataPropertyInLiteral: | 104 case IrOpcode::kJSStoreDataPropertyInLiteral: |
103 return ReduceJSStoreDataPropertyInLiteral(node); | 105 return ReduceJSStoreDataPropertyInLiteral(node); |
104 default: | 106 default: |
105 break; | 107 break; |
106 } | 108 } |
107 return NoChange(); | 109 return NoChange(); |
108 } | 110 } |
109 | 111 |
| 112 Reduction JSNativeContextSpecialization::ReduceJSAdd(Node* node) { |
| 113 // TODO(turbofan): This has to run together with the inlining and |
| 114 // native context specialization to be able to leverage the string |
| 115 // constant-folding for optimizing property access, but we should |
| 116 // nevertheless find a better home for this at some point. |
| 117 DCHECK_EQ(IrOpcode::kJSAdd, node->opcode()); |
| 118 |
| 119 // Constant-fold string concatenation. |
| 120 HeapObjectBinopMatcher m(node); |
| 121 if (m.left().HasValue() && m.left().Value()->IsString() && |
| 122 m.right().HasValue() && m.right().Value()->IsString()) { |
| 123 Handle<String> left = Handle<String>::cast(m.left().Value()); |
| 124 Handle<String> right = Handle<String>::cast(m.right().Value()); |
| 125 if (left->length() + right->length() <= String::kMaxLength) { |
| 126 Handle<String> result = |
| 127 factory()->NewConsString(left, right).ToHandleChecked(); |
| 128 Node* value = jsgraph()->HeapConstant(result); |
| 129 ReplaceWithValue(node, value); |
| 130 return Replace(value); |
| 131 } |
| 132 } |
| 133 return NoChange(); |
| 134 } |
| 135 |
110 Reduction JSNativeContextSpecialization::ReduceJSGetSuperConstructor( | 136 Reduction JSNativeContextSpecialization::ReduceJSGetSuperConstructor( |
111 Node* node) { | 137 Node* node) { |
112 DCHECK_EQ(IrOpcode::kJSGetSuperConstructor, node->opcode()); | 138 DCHECK_EQ(IrOpcode::kJSGetSuperConstructor, node->opcode()); |
113 Node* constructor = NodeProperties::GetValueInput(node, 0); | 139 Node* constructor = NodeProperties::GetValueInput(node, 0); |
114 | 140 |
115 // If deoptimization is disabled, we cannot optimize. | 141 // If deoptimization is disabled, we cannot optimize. |
116 if (!(flags() & kDeoptimizationEnabled)) return NoChange(); | 142 if (!(flags() & kDeoptimizationEnabled)) return NoChange(); |
117 | 143 |
118 // Check if the input is a known JSFunction. | 144 // Check if the input is a known JSFunction. |
119 HeapObjectMatcher m(constructor); | 145 HeapObjectMatcher m(constructor); |
(...skipping 2182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2302 return jsgraph()->javascript(); | 2328 return jsgraph()->javascript(); |
2303 } | 2329 } |
2304 | 2330 |
2305 SimplifiedOperatorBuilder* JSNativeContextSpecialization::simplified() const { | 2331 SimplifiedOperatorBuilder* JSNativeContextSpecialization::simplified() const { |
2306 return jsgraph()->simplified(); | 2332 return jsgraph()->simplified(); |
2307 } | 2333 } |
2308 | 2334 |
2309 } // namespace compiler | 2335 } // namespace compiler |
2310 } // namespace internal | 2336 } // namespace internal |
2311 } // namespace v8 | 2337 } // namespace v8 |
OLD | NEW |