OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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/hydrogen-bce.h" | 5 #include "src/hydrogen-bce.h" |
6 | 6 |
7 namespace v8 { | 7 namespace v8 { |
8 namespace internal { | 8 namespace internal { |
9 | 9 |
10 | 10 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 } else if (check->index()->IsSub()) { | 47 } else if (check->index()->IsSub()) { |
48 HSub* index = HSub::cast(check->index()); | 48 HSub* index = HSub::cast(check->index()); |
49 is_sub = true; | 49 is_sub = true; |
50 if (index->left()->IsConstant()) { | 50 if (index->left()->IsConstant()) { |
51 constant = HConstant::cast(index->left()); | 51 constant = HConstant::cast(index->left()); |
52 index_base = index->right(); | 52 index_base = index->right(); |
53 } else if (index->right()->IsConstant()) { | 53 } else if (index->right()->IsConstant()) { |
54 constant = HConstant::cast(index->right()); | 54 constant = HConstant::cast(index->right()); |
55 index_base = index->left(); | 55 index_base = index->left(); |
56 } | 56 } |
| 57 } else if (check->index()->IsConstant()) { |
| 58 index_base = check->block()->graph()->GetConstant0(); |
| 59 constant = HConstant::cast(check->index()); |
57 } | 60 } |
58 | 61 |
59 if (constant != NULL && constant->HasInteger32Value()) { | 62 if (constant != NULL && constant->HasInteger32Value()) { |
60 *offset = is_sub ? - constant->Integer32Value() | 63 *offset = is_sub ? - constant->Integer32Value() |
61 : constant->Integer32Value(); | 64 : constant->Integer32Value(); |
62 } else { | 65 } else { |
63 *offset = 0; | 66 *offset = 0; |
64 index_base = check->index(); | 67 index_base = check->index(); |
65 } | 68 } |
66 | 69 |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 int32_t upper_offset_; | 218 int32_t upper_offset_; |
216 HBasicBlock* basic_block_; | 219 HBasicBlock* basic_block_; |
217 HBoundsCheck* lower_check_; | 220 HBoundsCheck* lower_check_; |
218 HBoundsCheck* upper_check_; | 221 HBoundsCheck* upper_check_; |
219 BoundsCheckBbData* next_in_bb_; | 222 BoundsCheckBbData* next_in_bb_; |
220 BoundsCheckBbData* father_in_dt_; | 223 BoundsCheckBbData* father_in_dt_; |
221 | 224 |
222 void MoveIndexIfNecessary(HValue* index_raw, | 225 void MoveIndexIfNecessary(HValue* index_raw, |
223 HBoundsCheck* insert_before, | 226 HBoundsCheck* insert_before, |
224 HInstruction* end_of_scan_range) { | 227 HInstruction* end_of_scan_range) { |
225 if (!index_raw->IsAdd() && !index_raw->IsSub()) { | 228 // index_raw can be HAdd(index_base, offset), HSub(index_base, offset), |
226 // index_raw can be HAdd(index_base, offset), HSub(index_base, offset), | 229 // HConstant(offset) or index_base directly. |
227 // or index_base directly. In the latter case, no need to move anything. | 230 // In the latter case, no need to move anything. |
228 return; | 231 if (index_raw->IsAdd() || index_raw->IsSub()) { |
229 } | 232 HArithmeticBinaryOperation* index = |
230 HArithmeticBinaryOperation* index = | 233 HArithmeticBinaryOperation::cast(index_raw); |
231 HArithmeticBinaryOperation::cast(index_raw); | 234 HValue* left_input = index->left(); |
232 HValue* left_input = index->left(); | 235 HValue* right_input = index->right(); |
233 HValue* right_input = index->right(); | 236 bool must_move_index = false; |
234 bool must_move_index = false; | 237 bool must_move_left_input = false; |
235 bool must_move_left_input = false; | 238 bool must_move_right_input = false; |
236 bool must_move_right_input = false; | 239 for (HInstruction* cursor = end_of_scan_range; cursor != insert_before;) { |
237 for (HInstruction* cursor = end_of_scan_range; cursor != insert_before;) { | 240 if (cursor == left_input) must_move_left_input = true; |
238 if (cursor == left_input) must_move_left_input = true; | 241 if (cursor == right_input) must_move_right_input = true; |
239 if (cursor == right_input) must_move_right_input = true; | 242 if (cursor == index) must_move_index = true; |
240 if (cursor == index) must_move_index = true; | 243 if (cursor->previous() == NULL) { |
241 if (cursor->previous() == NULL) { | 244 cursor = cursor->block()->dominator()->end(); |
242 cursor = cursor->block()->dominator()->end(); | 245 } else { |
243 } else { | 246 cursor = cursor->previous(); |
244 cursor = cursor->previous(); | 247 } |
245 } | 248 } |
246 } | 249 if (must_move_index) { |
247 if (must_move_index) { | 250 index->Unlink(); |
248 index->Unlink(); | 251 index->InsertBefore(insert_before); |
249 index->InsertBefore(insert_before); | 252 } |
250 } | 253 // The BCE algorithm only selects mergeable bounds checks that share |
251 // The BCE algorithm only selects mergeable bounds checks that share | 254 // the same "index_base", so we'll only ever have to move constants. |
252 // the same "index_base", so we'll only ever have to move constants. | 255 if (must_move_left_input) { |
253 if (must_move_left_input) { | 256 HConstant::cast(left_input)->Unlink(); |
254 HConstant::cast(left_input)->Unlink(); | 257 HConstant::cast(left_input)->InsertBefore(index); |
255 HConstant::cast(left_input)->InsertBefore(index); | 258 } |
256 } | 259 if (must_move_right_input) { |
257 if (must_move_right_input) { | 260 HConstant::cast(right_input)->Unlink(); |
258 HConstant::cast(right_input)->Unlink(); | 261 HConstant::cast(right_input)->InsertBefore(index); |
259 HConstant::cast(right_input)->InsertBefore(index); | 262 } |
| 263 } else if (index_raw->IsConstant()) { |
| 264 HConstant* index = HConstant::cast(index_raw); |
| 265 bool must_move = false; |
| 266 for (HInstruction* cursor = end_of_scan_range; cursor != insert_before;) { |
| 267 if (cursor == index) must_move = true; |
| 268 if (cursor->previous() == NULL) { |
| 269 cursor = cursor->block()->dominator()->end(); |
| 270 } else { |
| 271 cursor = cursor->previous(); |
| 272 } |
| 273 } |
| 274 if (must_move) { |
| 275 index->Unlink(); |
| 276 index->InsertBefore(insert_before); |
| 277 } |
260 } | 278 } |
261 } | 279 } |
262 | 280 |
263 void TightenCheck(HBoundsCheck* original_check, | 281 void TightenCheck(HBoundsCheck* original_check, |
264 HBoundsCheck* tighter_check, | 282 HBoundsCheck* tighter_check, |
265 int32_t new_offset) { | 283 int32_t new_offset) { |
266 ASSERT(original_check->length() == tighter_check->length()); | 284 ASSERT(original_check->length() == tighter_check->length()); |
267 MoveIndexIfNecessary(tighter_check->index(), original_check, tighter_check); | 285 MoveIndexIfNecessary(tighter_check->index(), original_check, tighter_check); |
268 original_check->ReplaceAllUsesWith(original_check->index()); | 286 original_check->ReplaceAllUsesWith(original_check->index()); |
269 original_check->SetOperandAt(0, tighter_check->index()); | 287 original_check->SetOperandAt(0, tighter_check->index()); |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 if (data->FatherInDominatorTree()) { | 459 if (data->FatherInDominatorTree()) { |
442 table_.Insert(data->Key(), data->FatherInDominatorTree(), zone()); | 460 table_.Insert(data->Key(), data->FatherInDominatorTree(), zone()); |
443 } else { | 461 } else { |
444 table_.Delete(data->Key()); | 462 table_.Delete(data->Key()); |
445 } | 463 } |
446 data = data->NextInBasicBlock(); | 464 data = data->NextInBasicBlock(); |
447 } | 465 } |
448 } | 466 } |
449 | 467 |
450 } } // namespace v8::internal | 468 } } // namespace v8::internal |
OLD | NEW |