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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 HCheckTable* Copy(HBasicBlock* succ, Zone* zone) { | 120 HCheckTable* Copy(HBasicBlock* succ, Zone* zone) { |
121 HCheckTable* copy = new(phase_->zone()) HCheckTable(phase_); | 121 HCheckTable* copy = new(phase_->zone()) HCheckTable(phase_); |
122 for (int i = 0; i < size_; i++) { | 122 for (int i = 0; i < size_; i++) { |
123 HCheckTableEntry* old_entry = &entries_[i]; | 123 HCheckTableEntry* old_entry = &entries_[i]; |
124 HCheckTableEntry* new_entry = ©->entries_[i]; | 124 HCheckTableEntry* new_entry = ©->entries_[i]; |
125 // TODO(titzer): keep the check if this block dominates the successor? | 125 // TODO(titzer): keep the check if this block dominates the successor? |
126 new_entry->object_ = old_entry->object_; | 126 new_entry->object_ = old_entry->object_; |
127 new_entry->check_ = NULL; | 127 new_entry->check_ = NULL; |
128 new_entry->maps_ = old_entry->maps_->Copy(phase_->zone()); | 128 new_entry->maps_ = old_entry->maps_->Copy(phase_->zone()); |
129 } | 129 } |
130 if (succ->predecessors()->length() == 1) { | 130 copy->cursor_ = cursor_; |
131 HControlInstruction* end = succ->predecessors()->at(0)->end(); | 131 copy->size_ = size_; |
132 if (end->IsCompareMap() && end->SuccessorAt(0) == succ) { | 132 |
| 133 // Branch-sensitive analysis for certain comparisons may add more facts |
| 134 // to the state for the successor on the true branch. |
| 135 HControlInstruction* end = succ->predecessors()->at(0)->end(); |
| 136 if (succ->predecessors()->length() == 1 && end->SuccessorAt(0) == succ) { |
| 137 if (end->IsCompareMap()) { |
133 // Learn on the true branch of if(CompareMap(x)). | 138 // Learn on the true branch of if(CompareMap(x)). |
134 HCompareMap* cmp = HCompareMap::cast(end); | 139 HCompareMap* cmp = HCompareMap::cast(end); |
135 HValue* object = cmp->value()->ActualValue(); | 140 HValue* object = cmp->value()->ActualValue(); |
136 HCheckTableEntry* entry = copy->Find(object); | 141 HCheckTableEntry* entry = copy->Find(object); |
137 if (entry == NULL) { | 142 if (entry == NULL) { |
138 copy->Insert(object, cmp->map()); | 143 copy->Insert(object, cmp->map()); |
139 } else { | 144 } else { |
140 MapSet list = new(phase_->zone()) UniqueSet<Map>(); | 145 MapSet list = new(phase_->zone()) UniqueSet<Map>(); |
141 list->Add(cmp->map(), phase_->zone()); | 146 list->Add(cmp->map(), phase_->zone()); |
142 entry->maps_ = list; | 147 entry->maps_ = list; |
143 } | 148 } |
| 149 } else if (end->IsCompareObjectEqAndBranch()) { |
| 150 // Learn on the true branch of if(CmpObjectEq(x, y)). |
| 151 HCompareObjectEqAndBranch* cmp = |
| 152 HCompareObjectEqAndBranch::cast(end); |
| 153 HValue* left = cmp->left()->ActualValue(); |
| 154 HValue* right = cmp->right()->ActualValue(); |
| 155 HCheckTableEntry* le = copy->Find(left); |
| 156 HCheckTableEntry* re = copy->Find(right); |
| 157 if (le == NULL) { |
| 158 if (re != NULL) { |
| 159 copy->Insert(left, NULL, re->maps_->Copy(zone)); |
| 160 } |
| 161 } else if (re == NULL) { |
| 162 copy->Insert(right, NULL, le->maps_->Copy(zone)); |
| 163 } else { |
| 164 MapSet intersect = le->maps_->Intersect(re->maps_, zone); |
| 165 le->maps_ = intersect; |
| 166 re->maps_ = intersect->Copy(zone); |
| 167 } |
144 } | 168 } |
145 // TODO(titzer): is it worthwhile to learn on false branch too? | 169 // Learning on false branches requires storing negative facts. |
146 } | 170 } |
| 171 |
147 return copy; | 172 return copy; |
148 } | 173 } |
149 | 174 |
150 // Global analysis: Merge this state with the other incoming state. | 175 // Global analysis: Merge this state with the other incoming state. |
151 HCheckTable* Merge(HBasicBlock* succ, HCheckTable* that, Zone* zone) { | 176 HCheckTable* Merge(HBasicBlock* succ, HCheckTable* that, Zone* zone) { |
152 if (that->size_ == 0) { | 177 if (that->size_ == 0) { |
153 // If the other state is empty, simply reset. | 178 // If the other state is empty, simply reset. |
154 size_ = 0; | 179 size_ = 0; |
155 cursor_ = 0; | 180 cursor_ = 0; |
156 return this; | 181 return this; |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
527 PRINT_STAT(removed_cho); | 552 PRINT_STAT(removed_cho); |
528 PRINT_STAT(narrowed); | 553 PRINT_STAT(narrowed); |
529 PRINT_STAT(loads); | 554 PRINT_STAT(loads); |
530 PRINT_STAT(empty); | 555 PRINT_STAT(empty); |
531 PRINT_STAT(compares_true); | 556 PRINT_STAT(compares_true); |
532 PRINT_STAT(compares_false); | 557 PRINT_STAT(compares_false); |
533 PRINT_STAT(transitions); | 558 PRINT_STAT(transitions); |
534 } | 559 } |
535 | 560 |
536 } } // namespace v8::internal | 561 } } // namespace v8::internal |
OLD | NEW |