| 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-type-feedback.h" | 5 #include "src/compiler/js-type-feedback.h" |
| 6 | 6 |
| 7 #include "src/property-details.h" | 7 #include "src/property-details.h" |
| 8 | 8 |
| 9 #include "src/accessors.h" | 9 #include "src/accessors.h" |
| 10 #include "src/ast.h" | 10 #include "src/ast.h" |
| 11 #include "src/compiler.h" | 11 #include "src/compiler.h" |
| 12 #include "src/type-info.h" | 12 #include "src/type-info.h" |
| 13 | 13 |
| 14 #include "src/compiler/access-builder.h" | 14 #include "src/compiler/access-builder.h" |
| 15 #include "src/compiler/common-operator.h" | 15 #include "src/compiler/common-operator.h" |
| 16 #include "src/compiler/frame-states.h" | 16 #include "src/compiler/frame-states.h" |
| 17 #include "src/compiler/node-aux-data.h" | 17 #include "src/compiler/node-aux-data.h" |
| 18 #include "src/compiler/node-matchers.h" | 18 #include "src/compiler/node-matchers.h" |
| 19 #include "src/compiler/operator-properties.h" | 19 #include "src/compiler/operator-properties.h" |
| 20 #include "src/compiler/simplified-operator.h" | 20 #include "src/compiler/simplified-operator.h" |
| 21 | 21 |
| 22 namespace v8 { | 22 namespace v8 { |
| 23 namespace internal { | 23 namespace internal { |
| 24 namespace compiler { | 24 namespace compiler { |
| 25 | 25 |
| 26 enum LoadOrStore { LOAD, STORE }; | 26 enum LoadOrStore { LOAD, STORE }; |
| 27 | 27 |
| 28 // TODO(turbofan): fix deoptimization problems |
| 29 #define ENABLE_FAST_PROPERTY_LOADS false |
| 30 #define ENABLE_FAST_PROPERTY_STORES false |
| 31 |
| 28 JSTypeFeedbackTable::JSTypeFeedbackTable(Zone* zone) | 32 JSTypeFeedbackTable::JSTypeFeedbackTable(Zone* zone) |
| 29 : map_(TypeFeedbackIdMap::key_compare(), | 33 : type_feedback_id_map_(TypeFeedbackIdMap::key_compare(), |
| 30 TypeFeedbackIdMap::allocator_type(zone)) {} | 34 TypeFeedbackIdMap::allocator_type(zone)), |
| 35 feedback_vector_ic_slot_map_(TypeFeedbackIdMap::key_compare(), |
| 36 TypeFeedbackIdMap::allocator_type(zone)) {} |
| 31 | 37 |
| 32 | 38 |
| 33 void JSTypeFeedbackTable::Record(Node* node, TypeFeedbackId id) { | 39 void JSTypeFeedbackTable::Record(Node* node, TypeFeedbackId id) { |
| 34 map_.insert(std::make_pair(node->id(), id)); | 40 type_feedback_id_map_.insert(std::make_pair(node->id(), id)); |
| 35 } | 41 } |
| 36 | 42 |
| 37 | 43 |
| 44 void JSTypeFeedbackTable::Record(Node* node, FeedbackVectorICSlot slot) { |
| 45 feedback_vector_ic_slot_map_.insert(std::make_pair(node->id(), slot)); |
| 46 } |
| 47 |
| 48 |
| 38 Reduction JSTypeFeedbackSpecializer::Reduce(Node* node) { | 49 Reduction JSTypeFeedbackSpecializer::Reduce(Node* node) { |
| 39 switch (node->opcode()) { | 50 switch (node->opcode()) { |
| 40 case IrOpcode::kJSLoadProperty: { | 51 case IrOpcode::kJSLoadProperty: { |
| 41 HeapObjectMatcher<Name> match(node->InputAt(1)); | 52 HeapObjectMatcher<Name> match(node->InputAt(1)); |
| 42 if (match.HasValue() && match.Value().handle()->IsName()) { | 53 if (match.HasValue() && match.Value().handle()->IsName()) { |
| 43 // LoadProperty(o, "constant") => LoadNamed["constant"](o). | 54 // LoadProperty(o, "constant") => LoadNamed["constant"](o). |
| 44 Unique<Name> name = match.Value(); | 55 Unique<Name> name = match.Value(); |
| 45 const VectorSlotPair& feedback = | 56 const VectorSlotPair& feedback = |
| 46 LoadPropertyParametersOf(node->op()).feedback(); | 57 LoadPropertyParametersOf(node->op()).feedback(); |
| 47 node->set_op(jsgraph()->javascript()->LoadNamed(name, feedback, | 58 node->set_op(jsgraph()->javascript()->LoadNamed(name, feedback, |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 if (is_smi || is_double) { | 140 if (is_smi || is_double) { |
| 130 // TODO(turbofan): check type and deopt for SMI/double stores. | 141 // TODO(turbofan): check type and deopt for SMI/double stores. |
| 131 return false; | 142 return false; |
| 132 } | 143 } |
| 133 } | 144 } |
| 134 | 145 |
| 135 int index = map->instance_descriptors()->GetFieldIndex(number); | 146 int index = map->instance_descriptors()->GetFieldIndex(number); |
| 136 FieldIndex field_index = FieldIndex::ForPropertyIndex(*map, index, is_double); | 147 FieldIndex field_index = FieldIndex::ForPropertyIndex(*map, index, is_double); |
| 137 | 148 |
| 138 if (field_index.is_inobject()) { | 149 if (field_index.is_inobject()) { |
| 150 if (is_double && !map->IsUnboxedDoubleField(field_index)) { |
| 151 // TODO(turbofan): support for out-of-line (MutableHeapNumber) loads. |
| 152 return false; |
| 153 } |
| 139 access->offset = field_index.offset(); | 154 access->offset = field_index.offset(); |
| 140 return true; | 155 return true; |
| 141 } | 156 } |
| 142 | 157 |
| 143 // TODO(turbofan): handle out of object properties. | 158 // TODO(turbofan): handle out of object properties. |
| 144 return false; | 159 return false; |
| 145 } | 160 } |
| 146 | 161 |
| 147 | 162 |
| 148 static bool IsGlobalObject(Node* node) { | 163 static bool IsGlobalObject(Node* node) { |
| 149 return NodeProperties::IsTyped(node) && | 164 return NodeProperties::IsTyped(node) && |
| 150 NodeProperties::GetBounds(node).upper->Is(Type::GlobalObject()); | 165 NodeProperties::GetBounds(node).upper->Is(Type::GlobalObject()); |
| 151 } | 166 } |
| 152 | 167 |
| 153 | 168 |
| 154 Reduction JSTypeFeedbackSpecializer::ReduceJSLoadNamed(Node* node) { | 169 Reduction JSTypeFeedbackSpecializer::ReduceJSLoadNamed(Node* node) { |
| 155 DCHECK(node->opcode() == IrOpcode::kJSLoadNamed); | 170 DCHECK(node->opcode() == IrOpcode::kJSLoadNamed); |
| 156 Node* receiver = node->InputAt(0); | 171 Node* receiver = node->InputAt(0); |
| 157 if (IsGlobalObject(receiver)) { | 172 if (IsGlobalObject(receiver)) { |
| 158 return ReduceJSLoadNamedForGlobalVariable(node); | 173 return ReduceJSLoadNamedForGlobalVariable(node); |
| 159 } | 174 } |
| 160 | 175 |
| 161 if (!FLAG_turbo_deoptimization) return NoChange(); | 176 if (!FLAG_turbo_deoptimization) return NoChange(); |
| 162 Node* frame_state_before = GetFrameStateBefore(node); | 177 Node* frame_state_before = GetFrameStateBefore(node); |
| 163 if (frame_state_before == nullptr) return NoChange(); | 178 if (frame_state_before == nullptr) return NoChange(); |
| 164 | 179 |
| 165 // TODO(turbofan): handle vector-based type feedback. | 180 const LoadNamedParameters& p = LoadNamedParametersOf(node->op()); |
| 166 TypeFeedbackId id = js_type_feedback_->find(node); | 181 Handle<Name> name = p.name().handle(); |
| 167 if (id.IsNone() || oracle()->LoadInlineCacheState(id) == UNINITIALIZED) { | 182 SmallMapList maps; |
| 183 |
| 184 FeedbackVectorICSlot slot = js_type_feedback_->FindFeedbackVectorICSlot(node); |
| 185 if (slot.IsInvalid() || |
| 186 oracle()->LoadInlineCacheState(slot) == UNINITIALIZED) { |
| 187 // No type feedback ids or the load is uninitialized. |
| 168 return NoChange(); | 188 return NoChange(); |
| 169 } | 189 } |
| 190 if (p.load_ic() == NAMED) { |
| 191 oracle()->PropertyReceiverTypes(slot, name, &maps); |
| 192 } else { |
| 193 // The load named was originally a load property. |
| 194 bool is_string; // Unused. |
| 195 IcCheckType key_type; // Unused. |
| 196 oracle()->KeyedPropertyReceiverTypes(slot, &maps, &is_string, &key_type); |
| 197 } |
| 170 | 198 |
| 171 const LoadNamedParameters& p = LoadNamedParametersOf(node->op()); | |
| 172 SmallMapList maps; | |
| 173 Handle<Name> name = p.name().handle(); | |
| 174 Node* effect = NodeProperties::GetEffectInput(node); | 199 Node* effect = NodeProperties::GetEffectInput(node); |
| 175 GatherReceiverTypes(receiver, effect, id, name, &maps); | |
| 176 | 200 |
| 177 if (maps.length() != 1) return NoChange(); // TODO(turbofan): polymorphism | 201 if (maps.length() != 1) return NoChange(); // TODO(turbofan): polymorphism |
| 202 if (!ENABLE_FAST_PROPERTY_LOADS) return NoChange(); |
| 178 | 203 |
| 179 Handle<Map> map = maps.first(); | 204 Handle<Map> map = maps.first(); |
| 180 FieldAccess field_access; | 205 FieldAccess field_access; |
| 181 if (!GetInObjectFieldAccess(LOAD, map, name, &field_access)) { | 206 if (!GetInObjectFieldAccess(LOAD, map, name, &field_access)) { |
| 182 return NoChange(); | 207 return NoChange(); |
| 183 } | 208 } |
| 184 | 209 |
| 185 Node* control = NodeProperties::GetControlInput(node); | 210 Node* control = NodeProperties::GetControlInput(node); |
| 186 Node* check_success; | 211 Node* check_success; |
| 187 Node* check_failed; | 212 Node* check_failed; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 } | 294 } |
| 270 | 295 |
| 271 | 296 |
| 272 Reduction JSTypeFeedbackSpecializer::ReduceJSLoadProperty(Node* node) { | 297 Reduction JSTypeFeedbackSpecializer::ReduceJSLoadProperty(Node* node) { |
| 273 return NoChange(); | 298 return NoChange(); |
| 274 } | 299 } |
| 275 | 300 |
| 276 | 301 |
| 277 Reduction JSTypeFeedbackSpecializer::ReduceJSStoreNamed(Node* node) { | 302 Reduction JSTypeFeedbackSpecializer::ReduceJSStoreNamed(Node* node) { |
| 278 DCHECK(node->opcode() == IrOpcode::kJSStoreNamed); | 303 DCHECK(node->opcode() == IrOpcode::kJSStoreNamed); |
| 279 if (true) return NoChange(); // TODO(titzer): storenamed is broken | |
| 280 Node* frame_state_before = GetFrameStateBefore(node); | 304 Node* frame_state_before = GetFrameStateBefore(node); |
| 281 if (frame_state_before == nullptr) return NoChange(); | 305 if (frame_state_before == nullptr) return NoChange(); |
| 282 | 306 |
| 283 TypeFeedbackId id = js_type_feedback_->find(node); | 307 const StoreNamedParameters& p = StoreNamedParametersOf(node->op()); |
| 284 if (id.IsNone() || oracle()->StoreIsUninitialized(id)) return NoChange(); | 308 Handle<Name> name = p.name().handle(); |
| 309 SmallMapList maps; |
| 310 TypeFeedbackId id = js_type_feedback_->FindTypeFeedbackId(node); |
| 311 if (id.IsNone() || oracle()->StoreIsUninitialized(id) == UNINITIALIZED) { |
| 312 // No type feedback ids or the store is uninitialized. |
| 313 // TODO(titzer): no feedback from vector ICs from stores. |
| 314 return NoChange(); |
| 315 } else { |
| 316 if (p.store_ic() == NAMED) { |
| 317 oracle()->PropertyReceiverTypes(id, name, &maps); |
| 318 } else { |
| 319 // The named store was originally a store property. |
| 320 bool is_string; // Unused. |
| 321 IcCheckType key_type; // Unused. |
| 322 oracle()->KeyedPropertyReceiverTypes(id, &maps, &is_string, &key_type); |
| 323 } |
| 324 } |
| 285 | 325 |
| 286 const StoreNamedParameters& p = StoreNamedParametersOf(node->op()); | |
| 287 SmallMapList maps; | |
| 288 Handle<Name> name = p.name().handle(); | |
| 289 Node* receiver = node->InputAt(0); | 326 Node* receiver = node->InputAt(0); |
| 290 Node* effect = NodeProperties::GetEffectInput(node); | 327 Node* effect = NodeProperties::GetEffectInput(node); |
| 291 GatherReceiverTypes(receiver, effect, id, name, &maps); | |
| 292 | 328 |
| 293 if (maps.length() != 1) return NoChange(); // TODO(turbofan): polymorphism | 329 if (maps.length() != 1) return NoChange(); // TODO(turbofan): polymorphism |
| 294 | 330 |
| 331 if (!ENABLE_FAST_PROPERTY_STORES) return NoChange(); |
| 332 |
| 295 Handle<Map> map = maps.first(); | 333 Handle<Map> map = maps.first(); |
| 296 FieldAccess field_access; | 334 FieldAccess field_access; |
| 297 if (!GetInObjectFieldAccess(STORE, map, name, &field_access)) { | 335 if (!GetInObjectFieldAccess(STORE, map, name, &field_access)) { |
| 298 return NoChange(); | 336 return NoChange(); |
| 299 } | 337 } |
| 300 | 338 |
| 301 Node* control = NodeProperties::GetControlInput(node); | 339 Node* control = NodeProperties::GetControlInput(node); |
| 302 Node* check_success; | 340 Node* check_success; |
| 303 Node* check_failed; | 341 Node* check_failed; |
| 304 BuildMapCheck(receiver, map, true, effect, control, &check_success, | 342 BuildMapCheck(receiver, map, true, effect, control, &check_success, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 graph()->NewNode(common()->Branch(BranchHint::kTrue), cmp, control); | 384 graph()->NewNode(common()->Branch(BranchHint::kTrue), cmp, control); |
| 347 *success = graph()->NewNode(common()->IfTrue(), branch); | 385 *success = graph()->NewNode(common()->IfTrue(), branch); |
| 348 *fail = graph()->NewNode(common()->IfFalse(), branch); | 386 *fail = graph()->NewNode(common()->IfFalse(), branch); |
| 349 | 387 |
| 350 if (if_smi) { | 388 if (if_smi) { |
| 351 *fail = graph()->NewNode(common()->Merge(2), *fail, if_smi); | 389 *fail = graph()->NewNode(common()->Merge(2), *fail, if_smi); |
| 352 } | 390 } |
| 353 } | 391 } |
| 354 | 392 |
| 355 | 393 |
| 356 void JSTypeFeedbackSpecializer::GatherReceiverTypes(Node* receiver, | |
| 357 Node* effect, | |
| 358 TypeFeedbackId id, | |
| 359 Handle<Name> name, | |
| 360 SmallMapList* maps) { | |
| 361 // TODO(turbofan): filter maps by initial receiver map if known | |
| 362 // TODO(turbofan): filter maps by native context (if specializing) | |
| 363 // TODO(turbofan): filter maps by effect chain | |
| 364 oracle()->PropertyReceiverTypes(id, name, maps); | |
| 365 } | |
| 366 | |
| 367 | |
| 368 // Get the frame state before an operation if it exists and has a valid | 394 // Get the frame state before an operation if it exists and has a valid |
| 369 // bailout id. | 395 // bailout id. |
| 370 Node* JSTypeFeedbackSpecializer::GetFrameStateBefore(Node* node) { | 396 Node* JSTypeFeedbackSpecializer::GetFrameStateBefore(Node* node) { |
| 371 int count = OperatorProperties::GetFrameStateInputCount(node->op()); | 397 int count = OperatorProperties::GetFrameStateInputCount(node->op()); |
| 372 DCHECK_LE(count, 2); | 398 DCHECK_LE(count, 2); |
| 373 if (count == 2) { | 399 if (count == 2) { |
| 374 Node* frame_state = NodeProperties::GetFrameStateInput(node, 1); | 400 Node* frame_state = NodeProperties::GetFrameStateInput(node, 1); |
| 375 if (frame_state->opcode() == IrOpcode::kFrameState) { | 401 if (frame_state->opcode() == IrOpcode::kFrameState) { |
| 376 BailoutId id = OpParameter<FrameStateCallInfo>(node).bailout_id(); | 402 BailoutId id = OpParameter<FrameStateCallInfo>(node).bailout_id(); |
| 377 if (id != BailoutId::None()) return frame_state; | 403 if (id != BailoutId::None()) return frame_state; |
| 378 } | 404 } |
| 379 } | 405 } |
| 380 return nullptr; | 406 return nullptr; |
| 381 } | 407 } |
| 382 | 408 |
| 383 } // namespace compiler | 409 } // namespace compiler |
| 384 } // namespace internal | 410 } // namespace internal |
| 385 } // namespace v8 | 411 } // namespace v8 |
| OLD | NEW |