| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 3288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3299 ASSERT(new_check->index()->representation().IsInteger32()); | 3299 ASSERT(new_check->index()->representation().IsInteger32()); |
| 3300 | 3300 |
| 3301 if (new_offset > upper_offset_) { | 3301 if (new_offset > upper_offset_) { |
| 3302 upper_offset_ = new_offset; | 3302 upper_offset_ = new_offset; |
| 3303 } else if (new_offset < lower_offset_) { | 3303 } else if (new_offset < lower_offset_) { |
| 3304 lower_offset_ = new_offset; | 3304 lower_offset_ = new_offset; |
| 3305 } else { | 3305 } else { |
| 3306 ASSERT(false); | 3306 ASSERT(false); |
| 3307 } | 3307 } |
| 3308 | 3308 |
| 3309 BuildOffsetAdd(&added_index_, | 3309 Check()->SetOperandAt(0, Key()->IndexBase()); |
| 3310 &added_index_offset_, | 3310 Check()->set_offset(lower_offset_, upper_offset_); |
| 3311 Key()->IndexBase(), | |
| 3312 new_check->index()->representation(), | |
| 3313 lower_offset_); | |
| 3314 Check()->SetOperandAt(0, added_index_); | |
| 3315 BuildOffsetAdd(&added_length_, | |
| 3316 &added_length_offset_, | |
| 3317 Key()->Length(), | |
| 3318 new_check->length()->representation(), | |
| 3319 lower_offset_ - upper_offset_); | |
| 3320 Check()->SetOperandAt(1, added_length_); | |
| 3321 | |
| 3322 new_check->DeleteAndReplaceWith(NULL); | 3311 new_check->DeleteAndReplaceWith(NULL); |
| 3323 } | 3312 } |
| 3324 | 3313 |
| 3325 void RemoveZeroOperations() { | |
| 3326 RemoveZeroAdd(&added_index_, &added_index_offset_); | |
| 3327 RemoveZeroAdd(&added_length_, &added_length_offset_); | |
| 3328 } | |
| 3329 | |
| 3330 BoundsCheckBbData(BoundsCheckKey* key, | 3314 BoundsCheckBbData(BoundsCheckKey* key, |
| 3331 int32_t lower_offset, | 3315 int32_t lower_offset, |
| 3332 int32_t upper_offset, | 3316 int32_t upper_offset, |
| 3333 HBasicBlock* bb, | 3317 HBasicBlock* bb, |
| 3334 HBoundsCheck* check, | 3318 HBoundsCheck* check, |
| 3335 BoundsCheckBbData* next_in_bb, | 3319 BoundsCheckBbData* next_in_bb, |
| 3336 BoundsCheckBbData* father_in_dt) | 3320 BoundsCheckBbData* father_in_dt) |
| 3337 : key_(key), | 3321 : key_(key), |
| 3338 lower_offset_(lower_offset), | 3322 lower_offset_(lower_offset), |
| 3339 upper_offset_(upper_offset), | 3323 upper_offset_(upper_offset), |
| 3340 basic_block_(bb), | 3324 basic_block_(bb), |
| 3341 check_(check), | 3325 check_(check), |
| 3342 added_index_offset_(NULL), | |
| 3343 added_index_(NULL), | |
| 3344 added_length_offset_(NULL), | |
| 3345 added_length_(NULL), | |
| 3346 next_in_bb_(next_in_bb), | 3326 next_in_bb_(next_in_bb), |
| 3347 father_in_dt_(father_in_dt) { } | 3327 father_in_dt_(father_in_dt) { |
| 3328 ASSERT(check->index()->representation().IsInteger32()); |
| 3329 } |
| 3348 | 3330 |
| 3349 private: | 3331 private: |
| 3350 BoundsCheckKey* key_; | 3332 BoundsCheckKey* key_; |
| 3351 int32_t lower_offset_; | 3333 int32_t lower_offset_; |
| 3352 int32_t upper_offset_; | 3334 int32_t upper_offset_; |
| 3353 HBasicBlock* basic_block_; | 3335 HBasicBlock* basic_block_; |
| 3354 HBoundsCheck* check_; | 3336 HBoundsCheck* check_; |
| 3355 HConstant* added_index_offset_; | |
| 3356 HAdd* added_index_; | |
| 3357 HConstant* added_length_offset_; | |
| 3358 HAdd* added_length_; | |
| 3359 BoundsCheckBbData* next_in_bb_; | 3337 BoundsCheckBbData* next_in_bb_; |
| 3360 BoundsCheckBbData* father_in_dt_; | 3338 BoundsCheckBbData* father_in_dt_; |
| 3361 | |
| 3362 void BuildOffsetAdd(HAdd** add, | |
| 3363 HConstant** constant, | |
| 3364 HValue* original_value, | |
| 3365 Representation representation, | |
| 3366 int32_t new_offset) { | |
| 3367 HConstant* new_constant = new(BasicBlock()->zone()) | |
| 3368 HConstant(Handle<Object>(Smi::FromInt(new_offset)), | |
| 3369 Representation::Integer32()); | |
| 3370 if (*add == NULL) { | |
| 3371 new_constant->InsertBefore(Check()); | |
| 3372 *add = new(BasicBlock()->zone()) HAdd(NULL, | |
| 3373 original_value, | |
| 3374 new_constant); | |
| 3375 (*add)->AssumeRepresentation(representation); | |
| 3376 (*add)->InsertBefore(Check()); | |
| 3377 } else { | |
| 3378 new_constant->InsertBefore(*add); | |
| 3379 (*constant)->DeleteAndReplaceWith(new_constant); | |
| 3380 } | |
| 3381 *constant = new_constant; | |
| 3382 } | |
| 3383 | |
| 3384 void RemoveZeroAdd(HAdd** add, HConstant** constant) { | |
| 3385 if (*add != NULL && (*constant)->Integer32Value() == 0) { | |
| 3386 (*add)->DeleteAndReplaceWith((*add)->left()); | |
| 3387 (*constant)->DeleteAndReplaceWith(NULL); | |
| 3388 } | |
| 3389 } | |
| 3390 }; | 3339 }; |
| 3391 | 3340 |
| 3392 | 3341 |
| 3393 static bool BoundsCheckKeyMatch(void* key1, void* key2) { | 3342 static bool BoundsCheckKeyMatch(void* key1, void* key2) { |
| 3394 BoundsCheckKey* k1 = static_cast<BoundsCheckKey*>(key1); | 3343 BoundsCheckKey* k1 = static_cast<BoundsCheckKey*>(key1); |
| 3395 BoundsCheckKey* k2 = static_cast<BoundsCheckKey*>(key2); | 3344 BoundsCheckKey* k2 = static_cast<BoundsCheckKey*>(key2); |
| 3396 return k1->IndexBase() == k2->IndexBase() && k1->Length() == k2->Length(); | 3345 return k1->IndexBase() == k2->IndexBase() && k1->Length() == k2->Length(); |
| 3397 } | 3346 } |
| 3398 | 3347 |
| 3399 | 3348 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3471 } | 3420 } |
| 3472 } | 3421 } |
| 3473 | 3422 |
| 3474 for (int i = 0; i < bb->dominated_blocks()->length(); ++i) { | 3423 for (int i = 0; i < bb->dominated_blocks()->length(); ++i) { |
| 3475 EliminateRedundantBoundsChecks(bb->dominated_blocks()->at(i), table); | 3424 EliminateRedundantBoundsChecks(bb->dominated_blocks()->at(i), table); |
| 3476 } | 3425 } |
| 3477 | 3426 |
| 3478 for (BoundsCheckBbData* data = bb_data_list; | 3427 for (BoundsCheckBbData* data = bb_data_list; |
| 3479 data != NULL; | 3428 data != NULL; |
| 3480 data = data->NextInBasicBlock()) { | 3429 data = data->NextInBasicBlock()) { |
| 3481 data->RemoveZeroOperations(); | |
| 3482 if (data->FatherInDominatorTree()) { | 3430 if (data->FatherInDominatorTree()) { |
| 3483 table->Insert(data->Key(), data->FatherInDominatorTree(), zone()); | 3431 table->Insert(data->Key(), data->FatherInDominatorTree(), zone()); |
| 3484 } else { | 3432 } else { |
| 3485 table->Delete(data->Key()); | 3433 table->Delete(data->Key()); |
| 3486 } | 3434 } |
| 3487 } | 3435 } |
| 3488 } | 3436 } |
| 3489 | 3437 |
| 3490 | 3438 |
| 3491 void HGraph::EliminateRedundantBoundsChecks() { | 3439 void HGraph::EliminateRedundantBoundsChecks() { |
| (...skipping 5950 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9442 } | 9390 } |
| 9443 } | 9391 } |
| 9444 | 9392 |
| 9445 #ifdef DEBUG | 9393 #ifdef DEBUG |
| 9446 if (graph_ != NULL) graph_->Verify(false); // No full verify. | 9394 if (graph_ != NULL) graph_->Verify(false); // No full verify. |
| 9447 if (allocator_ != NULL) allocator_->Verify(); | 9395 if (allocator_ != NULL) allocator_->Verify(); |
| 9448 #endif | 9396 #endif |
| 9449 } | 9397 } |
| 9450 | 9398 |
| 9451 } } // namespace v8::internal | 9399 } } // namespace v8::internal |
| OLD | NEW |