Chromium Code Reviews| 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 768 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 779 if (block->last() == previous) { | 779 if (block->last() == previous) { |
| 780 block->set_last(this); | 780 block->set_last(this); |
| 781 } | 781 } |
| 782 if (position() == RelocInfo::kNoPosition && | 782 if (position() == RelocInfo::kNoPosition && |
| 783 previous->position() != RelocInfo::kNoPosition) { | 783 previous->position() != RelocInfo::kNoPosition) { |
| 784 set_position(previous->position()); | 784 set_position(previous->position()); |
| 785 } | 785 } |
| 786 } | 786 } |
| 787 | 787 |
| 788 | 788 |
| 789 bool HInstruction::Dominates(HInstruction* other) { | |
| 790 if (block() != other->block()) { | |
| 791 return block()->Dominates(other->block()); | |
| 792 } | |
| 793 // Both instructions are in the same basic block. This instruction | |
| 794 // should precede the other one in order to dominate it. | |
| 795 for (HInstruction* instr = next(); instr != NULL; instr = instr->next()) { | |
| 796 if (instr == other) { | |
| 797 return true; | |
| 798 } | |
| 799 } | |
| 800 return false; | |
| 801 } | |
| 802 | |
| 803 | |
| 789 #ifdef DEBUG | 804 #ifdef DEBUG |
| 790 void HInstruction::Verify() { | 805 void HInstruction::Verify() { |
| 791 // Verify that input operands are defined before use. | 806 // Verify that input operands are defined before use. |
| 792 HBasicBlock* cur_block = block(); | 807 HBasicBlock* cur_block = block(); |
| 793 for (int i = 0; i < OperandCount(); ++i) { | 808 for (int i = 0; i < OperandCount(); ++i) { |
| 794 HValue* other_operand = OperandAt(i); | 809 HValue* other_operand = OperandAt(i); |
| 795 if (other_operand == NULL) continue; | 810 if (other_operand == NULL) continue; |
| 796 HBasicBlock* other_block = other_operand->block(); | 811 HBasicBlock* other_block = other_operand->block(); |
| 797 if (cur_block == other_block) { | 812 if (cur_block == other_block) { |
| 798 if (!other_operand->IsPhi()) { | 813 if (!other_operand->IsPhi()) { |
| (...skipping 2551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3350 id(), Mnemonic(), dominator->id(), dominator->Mnemonic()); | 3365 id(), Mnemonic(), dominator->id(), dominator->Mnemonic()); |
| 3351 } | 3366 } |
| 3352 return; | 3367 return; |
| 3353 } | 3368 } |
| 3354 | 3369 |
| 3355 HAllocate* dominator_allocate = HAllocate::cast(dominator); | 3370 HAllocate* dominator_allocate = HAllocate::cast(dominator); |
| 3356 HValue* dominator_size = dominator_allocate->size(); | 3371 HValue* dominator_size = dominator_allocate->size(); |
| 3357 HValue* current_size = size(); | 3372 HValue* current_size = size(); |
| 3358 | 3373 |
| 3359 // TODO(hpayer): Add support for non-constant allocation in dominator. | 3374 // TODO(hpayer): Add support for non-constant allocation in dominator. |
| 3360 if (!current_size->IsInteger32Constant() || | 3375 if (!dominator_size->IsInteger32Constant()) { |
| 3361 !dominator_size->IsInteger32Constant()) { | |
| 3362 if (FLAG_trace_allocation_folding) { | 3376 if (FLAG_trace_allocation_folding) { |
| 3363 PrintF("#%d (%s) cannot fold into #%d (%s), dynamic allocation size\n", | 3377 PrintF("#%d (%s) cannot fold into #%d (%s), " |
| 3378 "dynamic allocation size in dominator\n", | |
| 3364 id(), Mnemonic(), dominator->id(), dominator->Mnemonic()); | 3379 id(), Mnemonic(), dominator->id(), dominator->Mnemonic()); |
| 3365 } | 3380 } |
| 3366 return; | 3381 return; |
| 3367 } | 3382 } |
| 3368 | 3383 |
| 3369 dominator_allocate = GetFoldableDominator(dominator_allocate); | 3384 dominator_allocate = GetFoldableDominator(dominator_allocate); |
| 3370 if (dominator_allocate == NULL) { | 3385 if (dominator_allocate == NULL) { |
| 3371 return; | 3386 return; |
| 3372 } | 3387 } |
| 3373 | 3388 |
| 3389 if (!current_size->IsInteger32Constant()) { | |
| 3390 HInstruction* current_instr = HInstruction::cast(current_size); | |
|
Michael Starzinger
2013/11/14 12:50:13
The size might be an HPhi, in which case this cast
Igor Sheludko
2013/11/27 12:52:01
HPhi can't happen here, since the current_size is
| |
| 3391 if (!current_instr->Dominates(dominator_allocate)) { | |
| 3392 if (FLAG_trace_allocation_folding) { | |
| 3393 PrintF("#%d (%s) cannot fold into #%d (%s), dynamic allocation size\n", | |
|
Michael Starzinger
2013/11/14 12:50:13
nit: The tracing text "dynamic allocation size" is
Igor Sheludko
2013/11/27 12:52:01
Done.
| |
| 3394 id(), Mnemonic(), dominator->id(), dominator->Mnemonic()); | |
| 3395 } | |
| 3396 return; | |
| 3397 } | |
| 3398 } | |
| 3399 | |
| 3374 ASSERT((IsNewSpaceAllocation() && | 3400 ASSERT((IsNewSpaceAllocation() && |
| 3375 dominator_allocate->IsNewSpaceAllocation()) || | 3401 dominator_allocate->IsNewSpaceAllocation()) || |
| 3376 (IsOldDataSpaceAllocation() && | 3402 (IsOldDataSpaceAllocation() && |
| 3377 dominator_allocate->IsOldDataSpaceAllocation()) || | 3403 dominator_allocate->IsOldDataSpaceAllocation()) || |
| 3378 (IsOldPointerSpaceAllocation() && | 3404 (IsOldPointerSpaceAllocation() && |
| 3379 dominator_allocate->IsOldPointerSpaceAllocation())); | 3405 dominator_allocate->IsOldPointerSpaceAllocation())); |
| 3380 | 3406 |
| 3381 // First update the size of the dominator allocate instruction. | 3407 // First update the size of the dominator allocate instruction. |
| 3382 dominator_size = dominator_allocate->size(); | 3408 dominator_size = dominator_allocate->size(); |
| 3383 int32_t original_object_size = | 3409 int32_t original_object_size = |
| 3384 HConstant::cast(dominator_size)->GetInteger32Constant(); | 3410 HConstant::cast(dominator_size)->GetInteger32Constant(); |
| 3385 int32_t dominator_size_constant = original_object_size; | 3411 int32_t dominator_size_constant = original_object_size; |
| 3386 int32_t current_size_constant = | |
| 3387 HConstant::cast(current_size)->GetInteger32Constant(); | |
| 3388 int32_t new_dominator_size = dominator_size_constant + current_size_constant; | |
| 3389 | 3412 |
| 3390 if (MustAllocateDoubleAligned()) { | 3413 if (MustAllocateDoubleAligned()) { |
| 3391 if (!dominator_allocate->MustAllocateDoubleAligned()) { | 3414 if (!dominator_allocate->MustAllocateDoubleAligned()) { |
| 3392 dominator_allocate->MakeDoubleAligned(); | 3415 dominator_allocate->MakeDoubleAligned(); |
| 3393 } | 3416 } |
| 3394 if ((dominator_size_constant & kDoubleAlignmentMask) != 0) { | 3417 if ((dominator_size_constant & kDoubleAlignmentMask) != 0) { |
| 3395 dominator_size_constant += kDoubleSize / 2; | 3418 dominator_size_constant += kDoubleSize / 2; |
| 3396 new_dominator_size += kDoubleSize / 2; | |
| 3397 } | 3419 } |
| 3398 } | 3420 } |
| 3399 | 3421 |
| 3400 if (new_dominator_size > Page::kMaxNonCodeHeapObjectSize) { | 3422 if (current_size->IsInteger32Constant()) { |
| 3401 if (FLAG_trace_allocation_folding) { | 3423 int32_t current_size_constant = |
| 3402 PrintF("#%d (%s) cannot fold into #%d (%s) due to size: %d\n", | 3424 HConstant::cast(current_size)->GetInteger32Constant(); |
| 3403 id(), Mnemonic(), dominator_allocate->id(), | 3425 int32_t new_dominator_size = |
| 3404 dominator_allocate->Mnemonic(), new_dominator_size); | 3426 dominator_size_constant + current_size_constant; |
| 3427 | |
| 3428 if (new_dominator_size > Page::kMaxNonCodeHeapObjectSize) { | |
| 3429 if (FLAG_trace_allocation_folding) { | |
| 3430 PrintF("#%d (%s) cannot fold into #%d (%s) due to size: %d\n", | |
| 3431 id(), Mnemonic(), dominator_allocate->id(), | |
| 3432 dominator_allocate->Mnemonic(), new_dominator_size); | |
| 3433 } | |
| 3434 return; | |
| 3405 } | 3435 } |
| 3406 return; | 3436 |
| 3437 HInstruction* new_dominator_size_constant = | |
| 3438 HConstant::CreateAndInsertBefore(zone, | |
| 3439 context(), | |
| 3440 new_dominator_size, | |
| 3441 Representation::None(), | |
| 3442 dominator_allocate); | |
| 3443 dominator_allocate->UpdateSize(new_dominator_size_constant); | |
| 3444 | |
| 3445 } else { | |
| 3446 HValue* new_dominator_size_constant = | |
| 3447 HConstant::CreateAndInsertBefore(zone, | |
| 3448 context(), | |
| 3449 dominator_size_constant, | |
| 3450 Representation::Integer32(), | |
| 3451 dominator_allocate); | |
| 3452 | |
| 3453 // Add old and new size together and insert | |
| 3454 current_size->ChangeRepresentation(Representation::Integer32()); | |
| 3455 | |
| 3456 HInstruction* new_dominator_size = HAdd::New(zone, context(), | |
|
Michael Starzinger
2013/11/14 12:50:13
Hmm, what happens of new_dominator_size gets bigge
| |
| 3457 new_dominator_size_constant, current_size); | |
| 3458 new_dominator_size->ClearFlag(HValue::kCanOverflow); | |
| 3459 new_dominator_size->ChangeRepresentation(Representation::Integer32()); | |
| 3460 | |
| 3461 new_dominator_size->InsertBefore(dominator_allocate); | |
| 3462 | |
| 3463 dominator_allocate->UpdateSize(new_dominator_size); | |
| 3407 } | 3464 } |
| 3408 | 3465 |
| 3409 HInstruction* new_dominator_size_constant = HConstant::CreateAndInsertBefore( | |
| 3410 zone, | |
| 3411 context(), | |
| 3412 new_dominator_size, | |
| 3413 Representation::None(), | |
| 3414 dominator_allocate); | |
| 3415 dominator_allocate->UpdateSize(new_dominator_size_constant); | |
| 3416 | |
| 3417 #ifdef VERIFY_HEAP | 3466 #ifdef VERIFY_HEAP |
| 3418 if (FLAG_verify_heap && dominator_allocate->IsNewSpaceAllocation()) { | 3467 if (FLAG_verify_heap && dominator_allocate->IsNewSpaceAllocation()) { |
| 3419 dominator_allocate->MakePrefillWithFiller(); | 3468 dominator_allocate->MakePrefillWithFiller(); |
| 3420 } else { | 3469 } else { |
| 3421 // TODO(hpayer): This is a short-term hack to make allocation mementos | 3470 // TODO(hpayer): This is a short-term hack to make allocation mementos |
| 3422 // work again in new space. | 3471 // work again in new space. |
| 3423 dominator_allocate->ClearNextMapWord(original_object_size); | 3472 dominator_allocate->ClearNextMapWord(original_object_size); |
| 3424 } | 3473 } |
| 3425 #else | 3474 #else |
| 3426 // TODO(hpayer): This is a short-term hack to make allocation mementos | 3475 // TODO(hpayer): This is a short-term hack to make allocation mementos |
| (...skipping 917 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4344 break; | 4393 break; |
| 4345 case kExternalMemory: | 4394 case kExternalMemory: |
| 4346 stream->Add("[external-memory]"); | 4395 stream->Add("[external-memory]"); |
| 4347 break; | 4396 break; |
| 4348 } | 4397 } |
| 4349 | 4398 |
| 4350 stream->Add("@%d", offset()); | 4399 stream->Add("@%d", offset()); |
| 4351 } | 4400 } |
| 4352 | 4401 |
| 4353 } } // namespace v8::internal | 4402 } } // namespace v8::internal |
| OLD | NEW |