| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 break; | 94 break; |
| 95 } | 95 } |
| 96 case HValue::kCheckMapValue: { | 96 case HValue::kCheckMapValue: { |
| 97 ReduceCheckMapValue(HCheckMapValue::cast(instr)); | 97 ReduceCheckMapValue(HCheckMapValue::cast(instr)); |
| 98 break; | 98 break; |
| 99 } | 99 } |
| 100 case HValue::kCheckHeapObject: { | 100 case HValue::kCheckHeapObject: { |
| 101 ReduceCheckHeapObject(HCheckHeapObject::cast(instr)); | 101 ReduceCheckHeapObject(HCheckHeapObject::cast(instr)); |
| 102 break; | 102 break; |
| 103 } | 103 } |
| 104 case HValue::kCompareObjectEqAndBranch: { |
| 105 ReduceCompareObjectEqAndBranch(HCompareObjectEqAndBranch::cast(instr)); |
| 106 break; |
| 107 } |
| 104 default: { | 108 default: { |
| 105 // If the instruction changes maps uncontrollably, drop everything. | 109 // If the instruction changes maps uncontrollably, drop everything. |
| 106 if (instr->CheckGVNFlag(kChangesMaps) || | 110 if (instr->CheckGVNFlag(kChangesMaps) || |
| 107 instr->CheckGVNFlag(kChangesOsrEntries)) { | 111 instr->CheckGVNFlag(kChangesOsrEntries)) { |
| 108 Kill(); | 112 Kill(); |
| 109 } | 113 } |
| 110 } | 114 } |
| 111 // Improvements possible: | 115 // Improvements possible: |
| 112 // - eliminate redundant HCheckSmi, HCheckInstanceType instructions | 116 // - eliminate redundant HCheckSmi, HCheckInstanceType instructions |
| 113 // - track which values have been HCheckHeapObject'd | 117 // - track which values have been HCheckHeapObject'd |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 } | 263 } |
| 260 | 264 |
| 261 void ReduceCheckHeapObject(HCheckHeapObject* instr) { | 265 void ReduceCheckHeapObject(HCheckHeapObject* instr) { |
| 262 if (FindMaps(instr->value()->ActualValue()) != NULL) { | 266 if (FindMaps(instr->value()->ActualValue()) != NULL) { |
| 263 // If the object has known maps, it's definitely a heap object. | 267 // If the object has known maps, it's definitely a heap object. |
| 264 instr->DeleteAndReplaceWith(instr->value()); | 268 instr->DeleteAndReplaceWith(instr->value()); |
| 265 INC_STAT(removed_cho_); | 269 INC_STAT(removed_cho_); |
| 266 } | 270 } |
| 267 } | 271 } |
| 268 | 272 |
| 273 void ReduceCompareObjectEqAndBranch(HCompareObjectEqAndBranch* instr) { |
| 274 HCheckMaps* removed = NULL; |
| 275 HValue* left = instr->left(); |
| 276 HValue* right = instr->right(); |
| 277 if (left->IsCheckMaps() && right->IsCheckMaps()) { |
| 278 HCheckMaps* left_check = HCheckMaps::cast(left); |
| 279 HCheckMaps* right_check = HCheckMaps::cast(right); |
| 280 MapSet left_maps = left_check->map_set().Copy(phase_->zone()); |
| 281 MapSet right_maps = right_check->map_set().Copy(phase_->zone()); |
| 282 if (left_maps->Equals(right_maps)) { |
| 283 // Object equality comparison guarantees one check suffices, so |
| 284 // eliminate the other. After LICM, we could easily find the correct |
| 285 // one (loop invariant object's map check could be hoisted out of loop). |
| 286 removed = left->block()->block_id() > right->block()->block_id() |
| 287 ? left_check : right_check; |
| 288 } |
| 289 } else if (left->IsCheckMaps() || right->IsCheckMaps()) { |
| 290 // For the case one side map check is eliminated by previous optimization. |
| 291 HValue* obj = left->IsCheckMaps() ? right : left; |
| 292 HCheckMaps* check = (obj == left) ? HCheckMaps::cast(right) |
| 293 : HCheckMaps::cast(left); |
| 294 MapSet obj_maps = FindMaps(obj); |
| 295 MapSet check_maps = check->map_set().Copy(phase_->zone()); |
| 296 if (obj_maps->IsSubset(check_maps)) { |
| 297 // Obj check is more strict; the remaining check is redundant. |
| 298 removed = check; |
| 299 } |
| 300 } |
| 301 |
| 302 if (removed != NULL) { |
| 303 // Check whether there is prior CheckHeapObject refering to the same |
| 304 // object as the removed CheckMaps. |
| 305 if (removed->previous()->IsCheckHeapObject()) { |
| 306 HCheckHeapObject* cho = HCheckHeapObject::cast(removed->previous()); |
| 307 if (cho->value() == removed->ActualValue()) { |
| 308 cho->DeleteAndReplaceWith(cho->value()); |
| 309 INC_STAT(removed_cho_); |
| 310 } |
| 311 } |
| 312 removed->DeleteAndReplaceWith(removed->ActualValue()); |
| 313 INC_STAT(removed_); |
| 314 } |
| 315 } |
| 316 |
| 269 void ReduceStoreNamedField(HStoreNamedField* instr) { | 317 void ReduceStoreNamedField(HStoreNamedField* instr) { |
| 270 HValue* object = instr->object()->ActualValue(); | 318 HValue* object = instr->object()->ActualValue(); |
| 271 if (instr->has_transition()) { | 319 if (instr->has_transition()) { |
| 272 // This store transitions the object to a new map. | 320 // This store transitions the object to a new map. |
| 273 Kill(object); | 321 Kill(object); |
| 274 Insert(object, MapConstant(instr->transition())); | 322 Insert(object, MapConstant(instr->transition())); |
| 275 } else if (IsMapAccess(instr->access())) { | 323 } else if (IsMapAccess(instr->access())) { |
| 276 // This is a store directly to the map field of the object. | 324 // This is a store directly to the map field of the object. |
| 277 Kill(object); | 325 Kill(object); |
| 278 if (!instr->value()->IsConstant()) return; | 326 if (!instr->value()->IsConstant()) return; |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 PRINT_STAT(removed_cho); | 575 PRINT_STAT(removed_cho); |
| 528 PRINT_STAT(narrowed); | 576 PRINT_STAT(narrowed); |
| 529 PRINT_STAT(loads); | 577 PRINT_STAT(loads); |
| 530 PRINT_STAT(empty); | 578 PRINT_STAT(empty); |
| 531 PRINT_STAT(compares_true); | 579 PRINT_STAT(compares_true); |
| 532 PRINT_STAT(compares_false); | 580 PRINT_STAT(compares_false); |
| 533 PRINT_STAT(transitions); | 581 PRINT_STAT(transitions); |
| 534 } | 582 } |
| 535 | 583 |
| 536 } } // namespace v8::internal | 584 } } // namespace v8::internal |
| OLD | NEW |