| OLD | NEW |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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/typed-optimization.h" | 5 #include "src/compiler/typed-optimization.h" |
| 6 | 6 |
| 7 #include "src/compilation-dependencies.h" | 7 #include "src/compilation-dependencies.h" |
| 8 #include "src/compiler/js-graph.h" | 8 #include "src/compiler/js-graph.h" |
| 9 #include "src/compiler/node-properties.h" | 9 #include "src/compiler/node-properties.h" |
| 10 #include "src/compiler/simplified-operator.h" | 10 #include "src/compiler/simplified-operator.h" |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 } | 90 } |
| 91 | 91 |
| 92 namespace { | 92 namespace { |
| 93 | 93 |
| 94 MaybeHandle<Map> GetStableMapFromObjectType(Type* object_type) { | 94 MaybeHandle<Map> GetStableMapFromObjectType(Type* object_type) { |
| 95 if (object_type->IsConstant() && | 95 if (object_type->IsConstant() && |
| 96 object_type->AsConstant()->Value()->IsHeapObject()) { | 96 object_type->AsConstant()->Value()->IsHeapObject()) { |
| 97 Handle<Map> object_map( | 97 Handle<Map> object_map( |
| 98 Handle<HeapObject>::cast(object_type->AsConstant()->Value())->map()); | 98 Handle<HeapObject>::cast(object_type->AsConstant()->Value())->map()); |
| 99 if (object_map->is_stable()) return object_map; | 99 if (object_map->is_stable()) return object_map; |
| 100 } else if (object_type->IsClass()) { | |
| 101 Handle<Map> object_map = object_type->AsClass()->Map(); | |
| 102 if (object_map->is_stable()) return object_map; | |
| 103 } | 100 } |
| 104 return MaybeHandle<Map>(); | 101 return MaybeHandle<Map>(); |
| 105 } | 102 } |
| 106 | 103 |
| 107 } // namespace | 104 } // namespace |
| 108 | 105 |
| 109 Reduction TypedOptimization::ReduceCheckMaps(Node* node) { | 106 Reduction TypedOptimization::ReduceCheckMaps(Node* node) { |
| 110 // The CheckMaps(o, ...map...) can be eliminated if map is stable and | 107 // The CheckMaps(o, ...map...) can be eliminated if map is stable, |
| 111 // either | 108 // o has type Constant(object) and map == object->map, and either |
| 112 // (a) o has type Constant(object) and map == object->map, or | |
| 113 // (b) o has type Class(map), | |
| 114 // and either | |
| 115 // (1) map cannot transition further, or | 109 // (1) map cannot transition further, or |
| 116 // (2) we can add a code dependency on the stability of map | 110 // (2) we can add a code dependency on the stability of map |
| 117 // (to guard the Constant type information). | 111 // (to guard the Constant type information). |
| 118 Node* const object = NodeProperties::GetValueInput(node, 0); | 112 Node* const object = NodeProperties::GetValueInput(node, 0); |
| 119 Type* const object_type = NodeProperties::GetType(object); | 113 Type* const object_type = NodeProperties::GetType(object); |
| 120 Node* const effect = NodeProperties::GetEffectInput(node); | 114 Node* const effect = NodeProperties::GetEffectInput(node); |
| 121 Handle<Map> object_map; | 115 Handle<Map> object_map; |
| 122 if (GetStableMapFromObjectType(object_type).ToHandle(&object_map)) { | 116 if (GetStableMapFromObjectType(object_type).ToHandle(&object_map)) { |
| 123 for (int i = 1; i < node->op()->ValueInputCount(); ++i) { | 117 for (int i = 1; i < node->op()->ValueInputCount(); ++i) { |
| 124 Node* const map = NodeProperties::GetValueInput(node, i); | 118 Node* const map = NodeProperties::GetValueInput(node, i); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 144 } | 138 } |
| 145 return NoChange(); | 139 return NoChange(); |
| 146 } | 140 } |
| 147 | 141 |
| 148 Reduction TypedOptimization::ReduceLoadField(Node* node) { | 142 Reduction TypedOptimization::ReduceLoadField(Node* node) { |
| 149 Node* const object = NodeProperties::GetValueInput(node, 0); | 143 Node* const object = NodeProperties::GetValueInput(node, 0); |
| 150 Type* const object_type = NodeProperties::GetType(object); | 144 Type* const object_type = NodeProperties::GetType(object); |
| 151 FieldAccess const& access = FieldAccessOf(node->op()); | 145 FieldAccess const& access = FieldAccessOf(node->op()); |
| 152 if (access.base_is_tagged == kTaggedBase && | 146 if (access.base_is_tagged == kTaggedBase && |
| 153 access.offset == HeapObject::kMapOffset) { | 147 access.offset == HeapObject::kMapOffset) { |
| 154 // We can replace LoadField[Map](o) with map if is stable and either | 148 // We can replace LoadField[Map](o) with map if is stable, and |
| 155 // (a) o has type Constant(object) and map == object->map, or | 149 // o has type Constant(object) and map == object->map, and either |
| 156 // (b) o has type Class(map), | |
| 157 // and either | |
| 158 // (1) map cannot transition further, or | 150 // (1) map cannot transition further, or |
| 159 // (2) deoptimization is enabled and we can add a code dependency on the | 151 // (2) deoptimization is enabled and we can add a code dependency on the |
| 160 // stability of map (to guard the Constant type information). | 152 // stability of map (to guard the Constant type information). |
| 161 Handle<Map> object_map; | 153 Handle<Map> object_map; |
| 162 if (GetStableMapFromObjectType(object_type).ToHandle(&object_map)) { | 154 if (GetStableMapFromObjectType(object_type).ToHandle(&object_map)) { |
| 163 if (object_map->CanTransition()) { | 155 if (object_map->CanTransition()) { |
| 164 if (flags() & kDeoptimizationEnabled) { | 156 if (flags() & kDeoptimizationEnabled) { |
| 165 dependencies()->AssumeMapStable(object_map); | 157 dependencies()->AssumeMapStable(object_map); |
| 166 } else { | 158 } else { |
| 167 return NoChange(); | 159 return NoChange(); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 | 240 |
| 249 Isolate* TypedOptimization::isolate() const { return jsgraph()->isolate(); } | 241 Isolate* TypedOptimization::isolate() const { return jsgraph()->isolate(); } |
| 250 | 242 |
| 251 SimplifiedOperatorBuilder* TypedOptimization::simplified() const { | 243 SimplifiedOperatorBuilder* TypedOptimization::simplified() const { |
| 252 return jsgraph()->simplified(); | 244 return jsgraph()->simplified(); |
| 253 } | 245 } |
| 254 | 246 |
| 255 } // namespace compiler | 247 } // namespace compiler |
| 256 } // namespace internal | 248 } // namespace internal |
| 257 } // namespace v8 | 249 } // namespace v8 |
| OLD | NEW |