Chromium Code Reviews| Index: src/hydrogen-instructions.cc |
| diff --git a/src/hydrogen-instructions.cc b/src/hydrogen-instructions.cc |
| index 39d59582beec3d1ba57cad734dc5713e5bdda976..68b811c4fa930feb5dbb17a1fdfb8a2152d2732a 100644 |
| --- a/src/hydrogen-instructions.cc |
| +++ b/src/hydrogen-instructions.cc |
| @@ -786,6 +786,21 @@ void HInstruction::InsertAfter(HInstruction* previous) { |
| } |
| +bool HInstruction::Dominates(HInstruction* other) { |
| + if (block() != other->block()) { |
| + return block()->Dominates(other->block()); |
| + } |
| + // Both instructions are in the same basic block. This instruction |
| + // should precede the other one in order to dominate it. |
| + for (HInstruction* instr = next(); instr != NULL; instr = instr->next()) { |
| + if (instr == other) { |
| + return true; |
| + } |
| + } |
| + return false; |
| +} |
| + |
| + |
| #ifdef DEBUG |
| void HInstruction::Verify() { |
| // Verify that input operands are defined before use. |
| @@ -3357,10 +3372,10 @@ void HAllocate::HandleSideEffectDominator(GVNFlag side_effect, |
| HValue* current_size = size(); |
| // TODO(hpayer): Add support for non-constant allocation in dominator. |
| - if (!current_size->IsInteger32Constant() || |
| - !dominator_size->IsInteger32Constant()) { |
| + if (!dominator_size->IsInteger32Constant()) { |
| if (FLAG_trace_allocation_folding) { |
| - PrintF("#%d (%s) cannot fold into #%d (%s), dynamic allocation size\n", |
| + PrintF("#%d (%s) cannot fold into #%d (%s), " |
| + "dynamic allocation size in dominator\n", |
| id(), Mnemonic(), dominator->id(), dominator->Mnemonic()); |
| } |
| return; |
| @@ -3371,6 +3386,17 @@ void HAllocate::HandleSideEffectDominator(GVNFlag side_effect, |
| return; |
| } |
| + if (!current_size->IsInteger32Constant()) { |
| + 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
|
| + if (!current_instr->Dominates(dominator_allocate)) { |
| + if (FLAG_trace_allocation_folding) { |
| + 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.
|
| + id(), Mnemonic(), dominator->id(), dominator->Mnemonic()); |
| + } |
| + return; |
| + } |
| + } |
| + |
| ASSERT((IsNewSpaceAllocation() && |
| dominator_allocate->IsNewSpaceAllocation()) || |
| (IsOldDataSpaceAllocation() && |
| @@ -3383,9 +3409,6 @@ void HAllocate::HandleSideEffectDominator(GVNFlag side_effect, |
| int32_t original_object_size = |
| HConstant::cast(dominator_size)->GetInteger32Constant(); |
| int32_t dominator_size_constant = original_object_size; |
| - int32_t current_size_constant = |
| - HConstant::cast(current_size)->GetInteger32Constant(); |
| - int32_t new_dominator_size = dominator_size_constant + current_size_constant; |
| if (MustAllocateDoubleAligned()) { |
| if (!dominator_allocate->MustAllocateDoubleAligned()) { |
| @@ -3393,26 +3416,52 @@ void HAllocate::HandleSideEffectDominator(GVNFlag side_effect, |
| } |
| if ((dominator_size_constant & kDoubleAlignmentMask) != 0) { |
| dominator_size_constant += kDoubleSize / 2; |
| - new_dominator_size += kDoubleSize / 2; |
| } |
| } |
| - 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_allocate->id(), |
| - dominator_allocate->Mnemonic(), new_dominator_size); |
| + if (current_size->IsInteger32Constant()) { |
| + int32_t current_size_constant = |
| + HConstant::cast(current_size)->GetInteger32Constant(); |
| + int32_t new_dominator_size = |
| + dominator_size_constant + current_size_constant; |
| + |
| + 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_allocate->id(), |
| + dominator_allocate->Mnemonic(), new_dominator_size); |
| + } |
| + return; |
| } |
| - return; |
| - } |
| - HInstruction* new_dominator_size_constant = HConstant::CreateAndInsertBefore( |
| - zone, |
| - context(), |
| - new_dominator_size, |
| - Representation::None(), |
| - dominator_allocate); |
| - dominator_allocate->UpdateSize(new_dominator_size_constant); |
| + HInstruction* new_dominator_size_constant = |
| + HConstant::CreateAndInsertBefore(zone, |
| + context(), |
| + new_dominator_size, |
| + Representation::None(), |
| + dominator_allocate); |
| + dominator_allocate->UpdateSize(new_dominator_size_constant); |
| + |
| + } else { |
| + HValue* new_dominator_size_constant = |
| + HConstant::CreateAndInsertBefore(zone, |
| + context(), |
| + dominator_size_constant, |
| + Representation::Integer32(), |
| + dominator_allocate); |
| + |
| + // Add old and new size together and insert |
| + current_size->ChangeRepresentation(Representation::Integer32()); |
| + |
| + 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
|
| + new_dominator_size_constant, current_size); |
| + new_dominator_size->ClearFlag(HValue::kCanOverflow); |
| + new_dominator_size->ChangeRepresentation(Representation::Integer32()); |
| + |
| + new_dominator_size->InsertBefore(dominator_allocate); |
| + |
| + dominator_allocate->UpdateSize(new_dominator_size); |
| + } |
| #ifdef VERIFY_HEAP |
| if (FLAG_verify_heap && dominator_allocate->IsNewSpaceAllocation()) { |