Chromium Code Reviews| Index: src/hydrogen-instructions.cc |
| diff --git a/src/hydrogen-instructions.cc b/src/hydrogen-instructions.cc |
| index 28511f714208f6fcc9eb84a4d1812723f09ba01b..32721d16bcd314405a4097c2495c956f9d4cc2fc 100644 |
| --- a/src/hydrogen-instructions.cc |
| +++ b/src/hydrogen-instructions.cc |
| @@ -3306,6 +3306,7 @@ Representation HUnaryMathOperation::RepresentationFromInputs() { |
| void HAllocate::HandleSideEffectDominator(GVNFlag side_effect, |
| HValue* dominator) { |
| ASSERT(side_effect == kChangesNewSpacePromotion); |
| + Zone* zone = dominator->block()->zone(); |
| if (!FLAG_use_allocation_folding) return; |
| // Try to fold allocations together with their dominating allocations. |
| @@ -3317,31 +3318,130 @@ void HAllocate::HandleSideEffectDominator(GVNFlag side_effect, |
| return; |
| } |
| - HAllocate* dominator_allocate_instr = HAllocate::cast(dominator); |
| - HValue* dominator_size = dominator_allocate_instr->size(); |
| + HAllocate* dominator_allocate = HAllocate::cast(dominator); |
| + HValue* dominator_size = dominator_allocate->size(); |
| HValue* current_size = size(); |
| - // We can just fold allocations that are guaranteed in new space. |
| + |
| // TODO(hpayer): Add support for non-constant allocation in dominator. |
| - if (!IsNewSpaceAllocation() || !current_size->IsInteger32Constant() || |
| - !dominator_allocate_instr->IsNewSpaceAllocation() || |
| + if (!current_size->IsInteger32Constant() || |
| !dominator_size->IsInteger32Constant()) { |
| if (FLAG_trace_allocation_folding) { |
| - PrintF("#%d (%s) cannot fold into #%d (%s)\n", |
| + PrintF("#%d (%s) cannot fold into #%d (%s), dynamic allocation size\n", |
| id(), Mnemonic(), dominator->id(), dominator->Mnemonic()); |
| } |
| return; |
| } |
| - // First update the size of the dominator allocate instruction. |
| int32_t dominator_size_constant = |
| HConstant::cast(dominator_size)->GetInteger32Constant(); |
| int32_t current_size_constant = |
| HConstant::cast(current_size)->GetInteger32Constant(); |
| + |
|
titzer
2013/08/06 12:24:12
This method is getting pretty big; suggest pulling
Hannes Payer (out of office)
2013/08/07 07:48:01
Done.
|
| + if (!IsFoldable(dominator_allocate)) { |
| + // We cannot hoist old space allocations over new space allocations. |
| + if (IsNewSpaceAllocation() || dominator_allocate->IsNewSpaceAllocation()) { |
| + if (FLAG_trace_allocation_folding) { |
| + PrintF("#%d (%s) cannot fold into #%d (%s), different spaces\n", |
| + id(), Mnemonic(), dominator->id(), dominator->Mnemonic()); |
| + } |
| + return; |
| + } |
| + |
| + // We can hoist old data space allocations over an old pointer space |
| + // allocation and vice versa. For that we have to check the dominator |
| + // of the dominator allocate instruction. |
| + HAllocate* previous_dominator = dominator_allocate->dominating_allocate(); |
| + if (previous_dominator == NULL) { |
| + set_dominating_allocate(dominator_allocate); |
| + if (FLAG_trace_allocation_folding) { |
| + PrintF("#%d (%s) cannot fold into #%d (%s), different spaces\n", |
| + id(), Mnemonic(), dominator->id(), dominator->Mnemonic()); |
| + } |
| + return; |
| + } |
| + |
| + // If we stored a dominator in our actual dominator, then it must be in |
| + // the space of the dominated allocation operation. We can hoist the old |
| + // space allocation over the actual dominator. |
| + dominator_allocate = previous_dominator; |
| + |
| + // We can just fold old space allocations that are in the same basic block, |
| + // since it is not guaranteed that we fill up the whole allocated old |
| + // space memory. |
| + // TODO(hpayer): Remove this limitation and add filler maps for each each |
| + // allocation as soon as we have store elimination. |
| + if (block()->block_id() != dominator_allocate->block()->block_id()) { |
| + if (FLAG_trace_allocation_folding) { |
| + PrintF("#%d (%s) cannot fold into #%d (%s), different basic blocks\n", |
| + id(), Mnemonic(), dominator_allocate->id(), |
| + dominator_allocate->Mnemonic()); |
| + } |
| + return; |
| + } |
| + |
| + ASSERT((IsOldDataSpaceAllocation() && |
| + dominator_allocate->IsOldDataSpaceAllocation()) || |
| + (IsOldPointerSpaceAllocation() && |
| + dominator_allocate->IsOldPointerSpaceAllocation())); |
| + |
| + HConstant* dominator_free_space_size = |
| + dominator_allocate->filler_free_space_size(); |
| + |
| + // We already hoisted one old space allocation, i.e., we already installed |
| + // a filler map. Hence, we just have to update the free space size. |
| + if (dominator_free_space_size != NULL) { |
| + int32_t current_free_space_size_constant = |
| + HConstant::cast(dominator_free_space_size)->GetInteger32Constant(); |
|
titzer
2013/08/06 12:24:12
I think this cast is redundant.
Hannes Payer (out of office)
2013/08/07 07:48:01
Done.
|
| + int32_t new_free_space_size_constant = current_free_space_size_constant + |
| + current_size_constant; |
| + HConstant* new_free_space_size = |
| + HConstant::New(zone, context(), new_free_space_size_constant); |
| + new_free_space_size->InsertBefore(dominator_free_space_size); |
| + dominator_free_space_size->DeleteAndReplaceWith(new_free_space_size); |
| + } else { |
| + // This is the first old space allocation that gets hoisted. We have to |
| + // install a filler map since the follwing allocation may cause a GC. |
| + HInstruction* free_space_instr = |
| + HInnerAllocatedObject::New(zone, context(), dominator_allocate, |
| + dominator_size_constant, type()); |
| + free_space_instr->InsertAfter(dominator_allocate); |
| + HConstant* filler_map = HConstant::New( |
| + zone, |
| + context(), |
| + isolate()->factory()->free_space_map(), |
| + UniqueValueId(isolate()->heap()->free_space_map())); |
| + filler_map->InsertAfter(free_space_instr); |
| + HInstruction* store_map = HStoreNamedField::New(zone, context(), |
| + free_space_instr, HObjectAccess::ForMap(), filler_map); |
| + store_map->SetFlag(HValue::kHasNoObservableSideEffects); |
| + store_map->InsertAfter(filler_map); |
| + |
| + HConstant* free_space_size = |
| + HConstant::New(zone, context(), current_size_constant); |
| + free_space_size->InsertAfter(store_map); |
| + dominator_allocate->set_filler_free_space_size(free_space_size); |
| + HObjectAccess access = |
| + HObjectAccess::ForJSObjectOffset(FreeSpace::kSizeOffset); |
| + HInstruction* store_size = HStoreNamedField::New(zone, context(), |
| + free_space_instr, access, free_space_size); |
| + store_size->SetFlag(HValue::kHasNoObservableSideEffects); |
| + store_size->InsertAfter(free_space_size); |
| + } |
| + } |
| + |
| + ASSERT((IsNewSpaceAllocation() && |
| + dominator_allocate->IsNewSpaceAllocation()) || |
| + (IsOldDataSpaceAllocation() && |
| + dominator_allocate->IsOldDataSpaceAllocation()) || |
| + (IsOldPointerSpaceAllocation() && |
| + dominator_allocate->IsOldPointerSpaceAllocation())); |
| + |
| + // First update the size of the dominator allocate instruction. |
| int32_t new_dominator_size = dominator_size_constant + current_size_constant; |
| if (MustAllocateDoubleAligned()) { |
| - if (!dominator_allocate_instr->MustAllocateDoubleAligned()) { |
| - dominator_allocate_instr->MakeDoubleAligned(); |
| + if (!dominator_allocate->MustAllocateDoubleAligned()) { |
| + dominator_allocate->MakeDoubleAligned(); |
| } |
| if ((dominator_size_constant & kDoubleAlignmentMask) != 0) { |
| dominator_size_constant += kDoubleSize / 2; |
| @@ -3352,21 +3452,19 @@ void HAllocate::HandleSideEffectDominator(GVNFlag side_effect, |
| if (new_dominator_size > Page::kMaxNonCodeHeapObjectSize) { |
| if (FLAG_trace_allocation_folding) { |
| PrintF("#%d (%s) cannot fold into #%d (%s) due to size: %d\n", |
| - id(), Mnemonic(), dominator->id(), dominator->Mnemonic(), |
| - new_dominator_size); |
| + id(), Mnemonic(), dominator_allocate->id(), |
| + dominator_allocate->Mnemonic(), new_dominator_size); |
| } |
| return; |
| } |
| - HBasicBlock* block = dominator->block(); |
| - Zone* zone = block->zone(); |
| HInstruction* new_dominator_size_constant = |
| HConstant::New(zone, context(), new_dominator_size); |
| - new_dominator_size_constant->InsertBefore(dominator_allocate_instr); |
| - dominator_allocate_instr->UpdateSize(new_dominator_size_constant); |
| + new_dominator_size_constant->InsertBefore(dominator_allocate); |
| + dominator_allocate->UpdateSize(new_dominator_size_constant); |
| #ifdef VERIFY_HEAP |
| - if (FLAG_verify_heap) { |
| - dominator_allocate_instr->MakePrefillWithFiller(); |
| + if (FLAG_verify_heap && dominator_allocate->IsNewSpaceAllocation()) { |
| + dominator_allocate->MakePrefillWithFiller(); |
| } |
| #endif |
| @@ -3374,7 +3472,7 @@ void HAllocate::HandleSideEffectDominator(GVNFlag side_effect, |
| HInstruction* dominated_allocate_instr = |
| HInnerAllocatedObject::New(zone, |
| context(), |
| - dominator_allocate_instr, |
| + dominator_allocate, |
| dominator_size_constant, |
| type()); |
| dominated_allocate_instr->InsertBefore(this); |