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 2527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3326 } | 3341 } |
3327 | 3342 |
3328 | 3343 |
3329 void HLoadGlobalGeneric::PrintDataTo(StringStream* stream) { | 3344 void HLoadGlobalGeneric::PrintDataTo(StringStream* stream) { |
3330 stream->Add("%o ", *name()); | 3345 stream->Add("%o ", *name()); |
3331 } | 3346 } |
3332 | 3347 |
3333 | 3348 |
3334 void HInnerAllocatedObject::PrintDataTo(StringStream* stream) { | 3349 void HInnerAllocatedObject::PrintDataTo(StringStream* stream) { |
3335 base_object()->PrintNameTo(stream); | 3350 base_object()->PrintNameTo(stream); |
3336 stream->Add(" offset %d", offset()); | 3351 stream->Add(" offset "); |
| 3352 offset()->PrintNameTo(stream); |
3337 } | 3353 } |
3338 | 3354 |
3339 | 3355 |
3340 void HStoreGlobalCell::PrintDataTo(StringStream* stream) { | 3356 void HStoreGlobalCell::PrintDataTo(StringStream* stream) { |
3341 stream->Add("[%p] = ", *cell().handle()); | 3357 stream->Add("[%p] = ", *cell().handle()); |
3342 value()->PrintNameTo(stream); | 3358 value()->PrintNameTo(stream); |
3343 if (!details_.IsDontDelete()) stream->Add(" (deleteable)"); | 3359 if (!details_.IsDontDelete()) stream->Add(" (deleteable)"); |
3344 if (details_.IsReadOnly()) stream->Add(" (read-only)"); | 3360 if (details_.IsReadOnly()) stream->Add(" (read-only)"); |
3345 } | 3361 } |
3346 | 3362 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3414 id(), Mnemonic(), dominator->id(), dominator->Mnemonic()); | 3430 id(), Mnemonic(), dominator->id(), dominator->Mnemonic()); |
3415 } | 3431 } |
3416 return; | 3432 return; |
3417 } | 3433 } |
3418 | 3434 |
3419 HAllocate* dominator_allocate = HAllocate::cast(dominator); | 3435 HAllocate* dominator_allocate = HAllocate::cast(dominator); |
3420 HValue* dominator_size = dominator_allocate->size(); | 3436 HValue* dominator_size = dominator_allocate->size(); |
3421 HValue* current_size = size(); | 3437 HValue* current_size = size(); |
3422 | 3438 |
3423 // TODO(hpayer): Add support for non-constant allocation in dominator. | 3439 // TODO(hpayer): Add support for non-constant allocation in dominator. |
3424 if (!current_size->IsInteger32Constant() || | 3440 if (!dominator_size->IsInteger32Constant()) { |
3425 !dominator_size->IsInteger32Constant()) { | |
3426 if (FLAG_trace_allocation_folding) { | 3441 if (FLAG_trace_allocation_folding) { |
3427 PrintF("#%d (%s) cannot fold into #%d (%s), dynamic allocation size\n", | 3442 PrintF("#%d (%s) cannot fold into #%d (%s), " |
| 3443 "dynamic allocation size in dominator\n", |
3428 id(), Mnemonic(), dominator->id(), dominator->Mnemonic()); | 3444 id(), Mnemonic(), dominator->id(), dominator->Mnemonic()); |
3429 } | 3445 } |
3430 return; | 3446 return; |
3431 } | 3447 } |
3432 | 3448 |
3433 dominator_allocate = GetFoldableDominator(dominator_allocate); | 3449 dominator_allocate = GetFoldableDominator(dominator_allocate); |
3434 if (dominator_allocate == NULL) { | 3450 if (dominator_allocate == NULL) { |
3435 return; | 3451 return; |
3436 } | 3452 } |
3437 | 3453 |
| 3454 if (!has_size_upper_bound()) { |
| 3455 if (FLAG_trace_allocation_folding) { |
| 3456 PrintF("#%d (%s) cannot fold into #%d (%s), " |
| 3457 "can't estimate total allocation size\n", |
| 3458 id(), Mnemonic(), dominator->id(), dominator->Mnemonic()); |
| 3459 } |
| 3460 return; |
| 3461 } |
| 3462 |
| 3463 if (!current_size->IsInteger32Constant()) { |
| 3464 // If it's not constant then it is a size_in_bytes calculation graph |
| 3465 // like this: (const_header_size + const_element_size * size). |
| 3466 ASSERT(current_size->IsInstruction()); |
| 3467 |
| 3468 HInstruction* current_instr = HInstruction::cast(current_size); |
| 3469 if (!current_instr->Dominates(dominator_allocate)) { |
| 3470 if (FLAG_trace_allocation_folding) { |
| 3471 PrintF("#%d (%s) cannot fold into #%d (%s), dynamic size " |
| 3472 "value does not dominate target allocation\n", |
| 3473 id(), Mnemonic(), dominator->id(), dominator->Mnemonic()); |
| 3474 } |
| 3475 return; |
| 3476 } |
| 3477 } |
| 3478 |
3438 ASSERT((IsNewSpaceAllocation() && | 3479 ASSERT((IsNewSpaceAllocation() && |
3439 dominator_allocate->IsNewSpaceAllocation()) || | 3480 dominator_allocate->IsNewSpaceAllocation()) || |
3440 (IsOldDataSpaceAllocation() && | 3481 (IsOldDataSpaceAllocation() && |
3441 dominator_allocate->IsOldDataSpaceAllocation()) || | 3482 dominator_allocate->IsOldDataSpaceAllocation()) || |
3442 (IsOldPointerSpaceAllocation() && | 3483 (IsOldPointerSpaceAllocation() && |
3443 dominator_allocate->IsOldPointerSpaceAllocation())); | 3484 dominator_allocate->IsOldPointerSpaceAllocation())); |
3444 | 3485 |
3445 // First update the size of the dominator allocate instruction. | 3486 // First update the size of the dominator allocate instruction. |
3446 dominator_size = dominator_allocate->size(); | 3487 dominator_size = dominator_allocate->size(); |
3447 int32_t original_object_size = | 3488 int32_t original_object_size = |
3448 HConstant::cast(dominator_size)->GetInteger32Constant(); | 3489 HConstant::cast(dominator_size)->GetInteger32Constant(); |
3449 int32_t dominator_size_constant = original_object_size; | 3490 int32_t dominator_size_constant = original_object_size; |
3450 int32_t current_size_constant = | 3491 |
3451 HConstant::cast(current_size)->GetInteger32Constant(); | 3492 if (MustAllocateDoubleAligned()) { |
3452 int32_t new_dominator_size = dominator_size_constant + current_size_constant; | 3493 if ((dominator_size_constant & kDoubleAlignmentMask) != 0) { |
| 3494 dominator_size_constant += kDoubleSize / 2; |
| 3495 } |
| 3496 } |
| 3497 |
| 3498 int32_t current_size_max_value = size_upper_bound()->GetInteger32Constant(); |
| 3499 int32_t new_dominator_size = dominator_size_constant + current_size_max_value; |
| 3500 |
| 3501 if (new_dominator_size > isolate()->heap()->MaxRegularSpaceAllocationSize()) { |
| 3502 if (FLAG_trace_allocation_folding) { |
| 3503 PrintF("#%d (%s) cannot fold into #%d (%s), " |
| 3504 "resulting allocation size is too big\n", |
| 3505 id(), Mnemonic(), dominator->id(), dominator->Mnemonic()); |
| 3506 } |
| 3507 return; |
| 3508 } |
| 3509 |
| 3510 HInstruction* new_dominator_size_value; |
| 3511 |
| 3512 if (current_size->IsInteger32Constant()) { |
| 3513 new_dominator_size_value = |
| 3514 HConstant::CreateAndInsertBefore(zone, |
| 3515 context(), |
| 3516 new_dominator_size, |
| 3517 Representation::None(), |
| 3518 dominator_allocate); |
| 3519 } else { |
| 3520 HValue* new_dominator_size_constant = |
| 3521 HConstant::CreateAndInsertBefore(zone, |
| 3522 context(), |
| 3523 dominator_size_constant, |
| 3524 Representation::Integer32(), |
| 3525 dominator_allocate); |
| 3526 |
| 3527 // Add old and new size together and insert |
| 3528 current_size->ChangeRepresentation(Representation::Integer32()); |
| 3529 |
| 3530 new_dominator_size_value = HAdd::New(zone, context(), |
| 3531 new_dominator_size_constant, current_size); |
| 3532 new_dominator_size_value->ClearFlag(HValue::kCanOverflow); |
| 3533 new_dominator_size_value->ChangeRepresentation(Representation::Integer32()); |
| 3534 |
| 3535 new_dominator_size_value->InsertBefore(dominator_allocate); |
| 3536 } |
| 3537 |
| 3538 dominator_allocate->UpdateSize(new_dominator_size_value); |
3453 | 3539 |
3454 if (MustAllocateDoubleAligned()) { | 3540 if (MustAllocateDoubleAligned()) { |
3455 if (!dominator_allocate->MustAllocateDoubleAligned()) { | 3541 if (!dominator_allocate->MustAllocateDoubleAligned()) { |
3456 dominator_allocate->MakeDoubleAligned(); | 3542 dominator_allocate->MakeDoubleAligned(); |
3457 } | 3543 } |
3458 if ((dominator_size_constant & kDoubleAlignmentMask) != 0) { | |
3459 dominator_size_constant += kDoubleSize / 2; | |
3460 new_dominator_size += kDoubleSize / 2; | |
3461 } | |
3462 } | 3544 } |
3463 | 3545 |
3464 if (new_dominator_size > isolate()->heap()->MaxRegularSpaceAllocationSize()) { | |
3465 if (FLAG_trace_allocation_folding) { | |
3466 PrintF("#%d (%s) cannot fold into #%d (%s) due to size: %d\n", | |
3467 id(), Mnemonic(), dominator_allocate->id(), | |
3468 dominator_allocate->Mnemonic(), new_dominator_size); | |
3469 } | |
3470 return; | |
3471 } | |
3472 | |
3473 HInstruction* new_dominator_size_constant = HConstant::CreateAndInsertBefore( | |
3474 zone, | |
3475 context(), | |
3476 new_dominator_size, | |
3477 Representation::None(), | |
3478 dominator_allocate); | |
3479 dominator_allocate->UpdateSize(new_dominator_size_constant); | |
3480 | |
3481 #ifdef VERIFY_HEAP | 3546 #ifdef VERIFY_HEAP |
3482 if (FLAG_verify_heap && dominator_allocate->IsNewSpaceAllocation()) { | 3547 if (FLAG_verify_heap && dominator_allocate->IsNewSpaceAllocation()) { |
3483 dominator_allocate->MakePrefillWithFiller(); | 3548 dominator_allocate->MakePrefillWithFiller(); |
3484 } else { | 3549 } else { |
3485 // TODO(hpayer): This is a short-term hack to make allocation mementos | 3550 // TODO(hpayer): This is a short-term hack to make allocation mementos |
3486 // work again in new space. | 3551 // work again in new space. |
3487 dominator_allocate->ClearNextMapWord(original_object_size); | 3552 dominator_allocate->ClearNextMapWord(original_object_size); |
3488 } | 3553 } |
3489 #else | 3554 #else |
3490 // TODO(hpayer): This is a short-term hack to make allocation mementos | 3555 // TODO(hpayer): This is a short-term hack to make allocation mementos |
(...skipping 938 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4429 break; | 4494 break; |
4430 case kExternalMemory: | 4495 case kExternalMemory: |
4431 stream->Add("[external-memory]"); | 4496 stream->Add("[external-memory]"); |
4432 break; | 4497 break; |
4433 } | 4498 } |
4434 | 4499 |
4435 stream->Add("@%d", offset()); | 4500 stream->Add("@%d", offset()); |
4436 } | 4501 } |
4437 | 4502 |
4438 } } // namespace v8::internal | 4503 } } // namespace v8::internal |
OLD | NEW |