Chromium Code Reviews| Index: src/hydrogen-instructions.cc |
| diff --git a/src/hydrogen-instructions.cc b/src/hydrogen-instructions.cc |
| index e816471ce604561601f90dfd08f41e25ed3d7495..cb5e91b074c1812d1b1ee346ccfe9be04355cc32 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. |
| @@ -3388,10 +3403,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; |
| @@ -3402,6 +3417,31 @@ void HAllocate::HandleSideEffectDominator(GVNFlag side_effect, |
| return; |
| } |
| + if (!current_size->IsInteger32Constant()) { |
| + if (!current_size->HasRange()) { |
| + if (FLAG_trace_allocation_folding) { |
| + PrintF("#%d (%s) cannot fold into #%d (%s), " |
| + "can't estimate total allocation size\n", |
| + id(), Mnemonic(), dominator->id(), dominator->Mnemonic()); |
| + } |
| + return; |
| + } |
| + |
| + // If it's not constant then it is a size_in_bytes calculation graph |
| + // like this: (const_header_size + const_element_size * size). |
| + ASSERT(current_size->IsInstruction()); |
| + |
| + HInstruction* current_instr = HInstruction::cast(current_size); |
| + if (!current_instr->Dominates(dominator_allocate)) { |
| + if (FLAG_trace_allocation_folding) { |
| + PrintF("#%d (%s) cannot fold into #%d (%s), dynamic size " |
| + "value does not dominate target allocation\n", |
| + id(), Mnemonic(), dominator->id(), dominator->Mnemonic()); |
| + } |
| + return; |
| + } |
| + } |
| + |
| ASSERT((IsNewSpaceAllocation() && |
| dominator_allocate->IsNewSpaceAllocation()) || |
| (IsOldDataSpaceAllocation() && |
| @@ -3414,36 +3454,77 @@ 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()) { |
| - dominator_allocate->MakeDoubleAligned(); |
| - } |
| if ((dominator_size_constant & kDoubleAlignmentMask) != 0) { |
| dominator_size_constant += kDoubleSize / 2; |
| - new_dominator_size += kDoubleSize / 2; |
| } |
| } |
| - if (new_dominator_size > isolate()->heap()->MaxRegularSpaceAllocationSize()) { |
| - 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()) { |
|
Hannes Payer (out of office)
2013/11/21 12:07:19
The size check code with tracing output is almost
|
| + 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 > |
| + isolate()->heap()->MaxRegularSpaceAllocationSize()) { |
| + if (FLAG_trace_allocation_folding) { |
| + PrintF("#%d (%s) cannot fold into #%d (%s), " |
| + "resulting allocation size is too big\n", |
| + id(), Mnemonic(), dominator->id(), dominator->Mnemonic()); |
| + } |
| + 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); |
| + |
| + } else { |
| + int32_t current_size_upper_bound = current_size->range()->upper(); |
| + int32_t new_dominator_size_upper_bound = |
| + dominator_size_constant + current_size_upper_bound; |
| + |
| + if (new_dominator_size_upper_bound > |
| + isolate()->heap()->MaxRegularSpaceAllocationSize()) { |
| + if (FLAG_trace_allocation_folding) { |
| + PrintF("#%d (%s) cannot fold into #%d (%s), " |
| + "resulting allocation size upper bound is too big\n", |
| + id(), Mnemonic(), dominator->id(), dominator->Mnemonic()); |
| + } |
| + return; |
| + } |
| + |
| + 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(), |
| + 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); |
| } |
| - HInstruction* new_dominator_size_constant = HConstant::CreateAndInsertBefore( |
| - zone, |
| - context(), |
| - new_dominator_size, |
| - Representation::None(), |
| - dominator_allocate); |
| - dominator_allocate->UpdateSize(new_dominator_size_constant); |
| + if (MustAllocateDoubleAligned()) { |
| + if (!dominator_allocate->MustAllocateDoubleAligned()) { |
| + dominator_allocate->MakeDoubleAligned(); |
| + } |
| + } |
| #ifdef VERIFY_HEAP |
| if (FLAG_verify_heap && dominator_allocate->IsNewSpaceAllocation()) { |