| 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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 } | 90 } |
| 91 case HValue::kTransitionElementsKind: { | 91 case HValue::kTransitionElementsKind: { |
| 92 ReduceTransitionElementsKind( | 92 ReduceTransitionElementsKind( |
| 93 HTransitionElementsKind::cast(instr)); | 93 HTransitionElementsKind::cast(instr)); |
| 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: { |
| 101 ReduceCheckHeapObject(HCheckHeapObject::cast(instr)); |
| 102 break; |
| 103 } |
| 100 default: { | 104 default: { |
| 101 // If the instruction changes maps uncontrollably, drop everything. | 105 // If the instruction changes maps uncontrollably, drop everything. |
| 102 if (instr->CheckGVNFlag(kChangesMaps) || | 106 if (instr->CheckGVNFlag(kChangesMaps) || |
| 103 instr->CheckGVNFlag(kChangesOsrEntries)) { | 107 instr->CheckGVNFlag(kChangesOsrEntries)) { |
| 104 Kill(); | 108 Kill(); |
| 105 } | 109 } |
| 106 } | 110 } |
| 107 // Improvements possible: | 111 // Improvements possible: |
| 108 // - eliminate HCheckSmi and HCheckHeapObject | 112 // - eliminate redundant HCheckSmi, HCheckInstanceType instructions |
| 113 // - track which values have been HCheckHeapObject'd |
| 109 } | 114 } |
| 110 | 115 |
| 111 return this; | 116 return this; |
| 112 } | 117 } |
| 113 | 118 |
| 114 // Global analysis: Copy state to successor block. | 119 // Global analysis: Copy state to successor block. |
| 115 HCheckTable* Copy(HBasicBlock* succ, Zone* zone) { | 120 HCheckTable* Copy(HBasicBlock* succ, Zone* zone) { |
| 116 HCheckTable* copy = new(phase_->zone()) HCheckTable(phase_); | 121 HCheckTable* copy = new(phase_->zone()) HCheckTable(phase_); |
| 117 for (int i = 0; i < size_; i++) { | 122 for (int i = 0; i < size_; i++) { |
| 118 HCheckTableEntry* old_entry = &entries_[i]; | 123 HCheckTableEntry* old_entry = &entries_[i]; |
| 119 HCheckTableEntry* new_entry = ©->entries_[i]; | 124 HCheckTableEntry* new_entry = ©->entries_[i]; |
| 120 // TODO(titzer): keep the check if this block dominates the successor? | 125 // TODO(titzer): keep the check if this block dominates the successor? |
| 121 new_entry->object_ = old_entry->object_; | 126 new_entry->object_ = old_entry->object_; |
| 122 new_entry->check_ = NULL; | 127 new_entry->check_ = NULL; |
| 123 new_entry->maps_ = old_entry->maps_->Copy(phase_->zone()); | 128 new_entry->maps_ = old_entry->maps_->Copy(phase_->zone()); |
| 124 } | 129 } |
| 130 if (succ->predecessors()->length() == 1) { |
| 131 HControlInstruction* end = succ->predecessors()->at(0)->end(); |
| 132 if (end->IsCompareMap() && end->SuccessorAt(0) == succ) { |
| 133 // Learn on the true branch of if(CompareMap(x)). |
| 134 HCompareMap* cmp = HCompareMap::cast(end); |
| 135 HValue* object = cmp->value()->ActualValue(); |
| 136 HCheckTableEntry* entry = copy->Find(object); |
| 137 if (entry == NULL) { |
| 138 copy->Insert(object, cmp->map()); |
| 139 } else { |
| 140 MapSet list = new(phase_->zone()) UniqueSet<Map>(); |
| 141 list->Add(cmp->map(), phase_->zone()); |
| 142 entry->maps_ = list; |
| 143 } |
| 144 } |
| 145 // TODO(titzer): is it worthwhile to learn on false branch too? |
| 146 } |
| 125 return copy; | 147 return copy; |
| 126 } | 148 } |
| 127 | 149 |
| 128 // Global analysis: Merge this state with the other incoming state. | 150 // Global analysis: Merge this state with the other incoming state. |
| 129 HCheckTable* Merge(HBasicBlock* succ, HCheckTable* that, Zone* zone) { | 151 HCheckTable* Merge(HBasicBlock* succ, HCheckTable* that, Zone* zone) { |
| 130 if (that->size_ == 0) { | 152 if (that->size_ == 0) { |
| 131 // If the other state is empty, simply reset. | 153 // If the other state is empty, simply reset. |
| 132 size_ = 0; | 154 size_ = 0; |
| 133 cursor_ = 0; | 155 cursor_ = 0; |
| 134 return this; | 156 return this; |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 maps->Clear(); | 251 maps->Clear(); |
| 230 maps->Add(map, phase_->zone()); | 252 maps->Add(map, phase_->zone()); |
| 231 } | 253 } |
| 232 } | 254 } |
| 233 } else { | 255 } else { |
| 234 // No prior information. | 256 // No prior information. |
| 235 Insert(object, map); | 257 Insert(object, map); |
| 236 } | 258 } |
| 237 } | 259 } |
| 238 | 260 |
| 261 void ReduceCheckHeapObject(HCheckHeapObject* instr) { |
| 262 if (FindMaps(instr->value()->ActualValue()) != NULL) { |
| 263 // If the object has known maps, it's definitely a heap object. |
| 264 instr->DeleteAndReplaceWith(instr->value()); |
| 265 INC_STAT(removed_cho_); |
| 266 } |
| 267 } |
| 268 |
| 239 void ReduceStoreNamedField(HStoreNamedField* instr) { | 269 void ReduceStoreNamedField(HStoreNamedField* instr) { |
| 240 HValue* object = instr->object()->ActualValue(); | 270 HValue* object = instr->object()->ActualValue(); |
| 241 if (instr->has_transition()) { | 271 if (instr->has_transition()) { |
| 242 // This store transitions the object to a new map. | 272 // This store transitions the object to a new map. |
| 243 Kill(object); | 273 Kill(object); |
| 244 Insert(object, MapConstant(instr->transition())); | 274 Insert(object, MapConstant(instr->transition())); |
| 245 } else if (IsMapAccess(instr->access())) { | 275 } else if (IsMapAccess(instr->access())) { |
| 246 // This is a store directly to the map field of the object. | 276 // This is a store directly to the map field of the object. |
| 247 Kill(object); | 277 Kill(object); |
| 248 if (!instr->value()->IsConstant()) return; | 278 if (!instr->value()->IsConstant()) return; |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 481 } | 511 } |
| 482 } | 512 } |
| 483 | 513 |
| 484 if (FLAG_trace_check_elimination) PrintStats(); | 514 if (FLAG_trace_check_elimination) PrintStats(); |
| 485 } | 515 } |
| 486 | 516 |
| 487 | 517 |
| 488 // Are we eliminated yet? | 518 // Are we eliminated yet? |
| 489 void HCheckEliminationPhase::PrintStats() { | 519 void HCheckEliminationPhase::PrintStats() { |
| 490 #if DEBUG | 520 #if DEBUG |
| 491 if (redundant_ > 0) PrintF(" redundant = %2d\n", redundant_); | 521 #define PRINT_STAT(x) if (x##_ > 0) PrintF(" %-16s = %2d\n", #x, x##_) |
| 492 if (removed_ > 0) PrintF(" removed = %2d\n", removed_); | 522 #else |
| 493 if (narrowed_ > 0) PrintF(" narrowed = %2d\n", narrowed_); | 523 #define PRINT_STAT(x) |
| 494 if (loads_ > 0) PrintF(" loads = %2d\n", loads_); | |
| 495 if (empty_ > 0) PrintF(" empty = %2d\n", empty_); | |
| 496 if (compares_true_ > 0) PrintF(" cmp_true = %2d\n", compares_true_); | |
| 497 if (compares_false_ > 0) PrintF(" cmp_false = %2d\n", compares_false_); | |
| 498 if (transitions_ > 0) PrintF(" transitions = %2d\n", transitions_); | |
| 499 #endif | 524 #endif |
| 525 PRINT_STAT(redundant); |
| 526 PRINT_STAT(removed); |
| 527 PRINT_STAT(removed_cho); |
| 528 PRINT_STAT(narrowed); |
| 529 PRINT_STAT(loads); |
| 530 PRINT_STAT(empty); |
| 531 PRINT_STAT(compares_true); |
| 532 PRINT_STAT(compares_false); |
| 533 PRINT_STAT(transitions); |
| 500 } | 534 } |
| 501 | 535 |
| 502 } } // namespace v8::internal | 536 } } // namespace v8::internal |
| OLD | NEW |