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/js-builtin-reducer.h" | 5 #include "src/compiler/js-builtin-reducer.h" |
6 | 6 |
7 #include "src/compilation-dependencies.h" | 7 #include "src/compilation-dependencies.h" |
8 #include "src/compiler/access-builder.h" | 8 #include "src/compiler/access-builder.h" |
9 #include "src/compiler/js-graph.h" | 9 #include "src/compiler/js-graph.h" |
10 #include "src/compiler/node-matchers.h" | 10 #include "src/compiler/node-matchers.h" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 Handle<Context> native_context) | 100 Handle<Context> native_context) |
101 : AdvancedReducer(editor), | 101 : AdvancedReducer(editor), |
102 dependencies_(dependencies), | 102 dependencies_(dependencies), |
103 flags_(flags), | 103 flags_(flags), |
104 jsgraph_(jsgraph), | 104 jsgraph_(jsgraph), |
105 native_context_(native_context), | 105 native_context_(native_context), |
106 type_cache_(TypeCache::Get()) {} | 106 type_cache_(TypeCache::Get()) {} |
107 | 107 |
108 namespace { | 108 namespace { |
109 | 109 |
| 110 // TODO(turbofan): Shall we move this to the NodeProperties? Or some (untyped) |
| 111 // alias analyzer? |
| 112 bool IsSame(Node* a, Node* b) { |
| 113 if (a == b) { |
| 114 return true; |
| 115 } else if (a->opcode() == IrOpcode::kCheckHeapObject) { |
| 116 return IsSame(a->InputAt(0), b); |
| 117 } else if (b->opcode() == IrOpcode::kCheckHeapObject) { |
| 118 return IsSame(a, b->InputAt(0)); |
| 119 } |
| 120 return false; |
| 121 } |
| 122 |
110 MaybeHandle<Map> GetMapWitness(Node* node) { | 123 MaybeHandle<Map> GetMapWitness(Node* node) { |
111 Node* receiver = NodeProperties::GetValueInput(node, 1); | 124 Node* receiver = NodeProperties::GetValueInput(node, 1); |
112 Node* effect = NodeProperties::GetEffectInput(node); | 125 Node* effect = NodeProperties::GetEffectInput(node); |
113 // Check if the {node} is dominated by a CheckMaps with a single map | 126 // Check if the {node} is dominated by a CheckMaps with a single map |
114 // for the {receiver}, and if so use that map for the lowering below. | 127 // for the {receiver}, and if so use that map for the lowering below. |
115 for (Node* dominator = effect;;) { | 128 for (Node* dominator = effect;;) { |
116 if (dominator->opcode() == IrOpcode::kCheckMaps && | 129 if (dominator->opcode() == IrOpcode::kCheckMaps && |
117 dominator->InputAt(0) == receiver) { | 130 IsSame(dominator->InputAt(0), receiver)) { |
118 if (dominator->op()->ValueInputCount() == 2) { | 131 if (dominator->op()->ValueInputCount() == 2) { |
119 HeapObjectMatcher m(dominator->InputAt(1)); | 132 HeapObjectMatcher m(dominator->InputAt(1)); |
120 if (m.HasValue()) return Handle<Map>::cast(m.Value()); | 133 if (m.HasValue()) return Handle<Map>::cast(m.Value()); |
121 } | 134 } |
122 return MaybeHandle<Map>(); | 135 return MaybeHandle<Map>(); |
123 } | 136 } |
124 if (dominator->op()->EffectInputCount() != 1) { | 137 if (dominator->op()->EffectInputCount() != 1) { |
125 // Didn't find any appropriate CheckMaps node. | 138 // Didn't find any appropriate CheckMaps node. |
126 return MaybeHandle<Map>(); | 139 return MaybeHandle<Map>(); |
127 } | 140 } |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 } | 337 } |
325 return NoChange(); | 338 return NoChange(); |
326 } | 339 } |
327 | 340 |
328 namespace { | 341 namespace { |
329 | 342 |
330 bool HasInstanceTypeWitness(Node* receiver, Node* effect, | 343 bool HasInstanceTypeWitness(Node* receiver, Node* effect, |
331 InstanceType instance_type) { | 344 InstanceType instance_type) { |
332 for (Node* dominator = effect;;) { | 345 for (Node* dominator = effect;;) { |
333 if (dominator->opcode() == IrOpcode::kCheckMaps && | 346 if (dominator->opcode() == IrOpcode::kCheckMaps && |
334 dominator->InputAt(0) == receiver) { | 347 IsSame(dominator->InputAt(0), receiver)) { |
335 // Check if all maps have the given {instance_type}. | 348 // Check if all maps have the given {instance_type}. |
336 for (int i = 1; i < dominator->op()->ValueInputCount(); ++i) { | 349 for (int i = 1; i < dominator->op()->ValueInputCount(); ++i) { |
337 Node* const map = NodeProperties::GetValueInput(dominator, i); | 350 Node* const map = NodeProperties::GetValueInput(dominator, i); |
338 Type* const map_type = NodeProperties::GetType(map); | 351 Type* const map_type = NodeProperties::GetType(map); |
339 if (!map_type->IsHeapConstant()) return false; | 352 if (!map_type->IsHeapConstant()) return false; |
340 Handle<Map> const map_value = | 353 Handle<Map> const map_value = |
341 Handle<Map>::cast(map_type->AsHeapConstant()->Value()); | 354 Handle<Map>::cast(map_type->AsHeapConstant()->Value()); |
342 if (map_value->instance_type() != instance_type) return false; | 355 if (map_value->instance_type() != instance_type) return false; |
343 } | 356 } |
344 return true; | 357 return true; |
(...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
915 Node* GetStringWitness(Node* node) { | 928 Node* GetStringWitness(Node* node) { |
916 Node* receiver = NodeProperties::GetValueInput(node, 1); | 929 Node* receiver = NodeProperties::GetValueInput(node, 1); |
917 Type* receiver_type = NodeProperties::GetType(receiver); | 930 Type* receiver_type = NodeProperties::GetType(receiver); |
918 Node* effect = NodeProperties::GetEffectInput(node); | 931 Node* effect = NodeProperties::GetEffectInput(node); |
919 if (receiver_type->Is(Type::String())) return receiver; | 932 if (receiver_type->Is(Type::String())) return receiver; |
920 // Check if the {node} is dominated by a CheckString renaming for | 933 // Check if the {node} is dominated by a CheckString renaming for |
921 // it's {receiver}, and if so use that renaming as {receiver} for | 934 // it's {receiver}, and if so use that renaming as {receiver} for |
922 // the lowering below. | 935 // the lowering below. |
923 for (Node* dominator = effect;;) { | 936 for (Node* dominator = effect;;) { |
924 if (dominator->opcode() == IrOpcode::kCheckString && | 937 if (dominator->opcode() == IrOpcode::kCheckString && |
925 dominator->InputAt(0) == receiver) { | 938 IsSame(dominator->InputAt(0), receiver)) { |
926 return dominator; | 939 return dominator; |
927 } | 940 } |
928 if (dominator->op()->EffectInputCount() != 1) { | 941 if (dominator->op()->EffectInputCount() != 1) { |
929 // Didn't find any appropriate CheckString node. | 942 // Didn't find any appropriate CheckString node. |
930 return nullptr; | 943 return nullptr; |
931 } | 944 } |
932 dominator = NodeProperties::GetEffectInput(dominator); | 945 dominator = NodeProperties::GetEffectInput(dominator); |
933 } | 946 } |
934 } | 947 } |
935 | 948 |
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1443 return jsgraph()->simplified(); | 1456 return jsgraph()->simplified(); |
1444 } | 1457 } |
1445 | 1458 |
1446 JSOperatorBuilder* JSBuiltinReducer::javascript() const { | 1459 JSOperatorBuilder* JSBuiltinReducer::javascript() const { |
1447 return jsgraph()->javascript(); | 1460 return jsgraph()->javascript(); |
1448 } | 1461 } |
1449 | 1462 |
1450 } // namespace compiler | 1463 } // namespace compiler |
1451 } // namespace internal | 1464 } // namespace internal |
1452 } // namespace v8 | 1465 } // namespace v8 |
OLD | NEW |