| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/compiler/live-range-separator.h" | 5 #include "src/compiler/live-range-separator.h" |
| 6 #include "src/compiler/register-allocator.h" | 6 #include "src/compiler/register-allocator.h" |
| 7 | 7 |
| 8 namespace v8 { | 8 namespace v8 { |
| 9 namespace internal { | 9 namespace internal { |
| 10 namespace compiler { | 10 namespace compiler { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 range->SetSplinter(splinter); | 51 range->SetSplinter(splinter); |
| 52 } | 52 } |
| 53 Zone *zone = data->allocation_zone(); | 53 Zone *zone = data->allocation_zone(); |
| 54 TRACE("creating splinter for range %d between %d and %d\n", range->vreg(), | 54 TRACE("creating splinter for range %d between %d and %d\n", range->vreg(), |
| 55 start.ToInstructionIndex(), end.ToInstructionIndex()); | 55 start.ToInstructionIndex(), end.ToInstructionIndex()); |
| 56 range->Splinter(start, end, zone); | 56 range->Splinter(start, end, zone); |
| 57 } | 57 } |
| 58 } | 58 } |
| 59 | 59 |
| 60 | 60 |
| 61 int FirstInstruction(const UseInterval *interval) { | |
| 62 LifetimePosition start = interval->start(); | |
| 63 int ret = start.ToInstructionIndex(); | |
| 64 if (start.IsInstructionPosition() && start.IsEnd()) { | |
| 65 ++ret; | |
| 66 } | |
| 67 return ret; | |
| 68 } | |
| 69 | |
| 70 | |
| 71 int LastInstruction(const UseInterval *interval) { | |
| 72 LifetimePosition end = interval->end(); | |
| 73 int ret = end.ToInstructionIndex(); | |
| 74 if (end.IsGapPosition() || end.IsStart()) { | |
| 75 --ret; | |
| 76 } | |
| 77 return ret; | |
| 78 } | |
| 79 | |
| 80 | |
| 81 void SplinterLiveRange(TopLevelLiveRange *range, RegisterAllocationData *data) { | 61 void SplinterLiveRange(TopLevelLiveRange *range, RegisterAllocationData *data) { |
| 82 const InstructionSequence *code = data->code(); | 62 const InstructionSequence *code = data->code(); |
| 83 UseInterval *interval = range->first_interval(); | 63 UseInterval *interval = range->first_interval(); |
| 84 | 64 |
| 85 LifetimePosition first_cut = LifetimePosition::Invalid(); | 65 LifetimePosition first_cut = LifetimePosition::Invalid(); |
| 86 LifetimePosition last_cut = LifetimePosition::Invalid(); | 66 LifetimePosition last_cut = LifetimePosition::Invalid(); |
| 87 | 67 |
| 88 while (interval != nullptr) { | 68 while (interval != nullptr) { |
| 89 UseInterval *next_interval = interval->next(); | 69 UseInterval *next_interval = interval->next(); |
| 90 const InstructionBlock *first_block = | 70 const InstructionBlock *first_block = |
| 91 code->GetInstructionBlock(FirstInstruction(interval)); | 71 code->GetInstructionBlock(interval->FirstInstructionIndex()); |
| 92 const InstructionBlock *last_block = | 72 const InstructionBlock *last_block = |
| 93 code->GetInstructionBlock(LastInstruction(interval)); | 73 code->GetInstructionBlock(interval->LastInstructionIndex()); |
| 94 int first_block_nr = first_block->rpo_number().ToInt(); | 74 int first_block_nr = first_block->rpo_number().ToInt(); |
| 95 int last_block_nr = last_block->rpo_number().ToInt(); | 75 int last_block_nr = last_block->rpo_number().ToInt(); |
| 96 for (int block_id = first_block_nr; block_id <= last_block_nr; ++block_id) { | 76 for (int block_id = first_block_nr; block_id <= last_block_nr; ++block_id) { |
| 97 const InstructionBlock *current_block = | 77 const InstructionBlock *current_block = |
| 98 code->InstructionBlockAt(RpoNumber::FromInt(block_id)); | 78 code->InstructionBlockAt(RpoNumber::FromInt(block_id)); |
| 99 if (current_block->IsDeferred()) { | 79 if (current_block->IsDeferred()) { |
| 100 if (!first_cut.IsValid()) { | 80 if (!first_cut.IsValid()) { |
| 101 first_cut = LifetimePosition::GapFromInstructionIndex( | 81 first_cut = LifetimePosition::GapFromInstructionIndex( |
| 102 current_block->first_instruction_index()); | 82 current_block->first_instruction_index()); |
| 103 } | 83 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 122 } // namespace | 102 } // namespace |
| 123 | 103 |
| 124 | 104 |
| 125 void LiveRangeSeparator::Splinter() { | 105 void LiveRangeSeparator::Splinter() { |
| 126 size_t virt_reg_count = data()->live_ranges().size(); | 106 size_t virt_reg_count = data()->live_ranges().size(); |
| 127 for (size_t vreg = 0; vreg < virt_reg_count; ++vreg) { | 107 for (size_t vreg = 0; vreg < virt_reg_count; ++vreg) { |
| 128 TopLevelLiveRange *range = data()->live_ranges()[vreg]; | 108 TopLevelLiveRange *range = data()->live_ranges()[vreg]; |
| 129 if (range == nullptr || range->IsEmpty() || range->IsSplinter()) { | 109 if (range == nullptr || range->IsEmpty() || range->IsSplinter()) { |
| 130 continue; | 110 continue; |
| 131 } | 111 } |
| 132 SplinterLiveRange(range, data()); | 112 int first_instr = range->first_interval()->FirstInstructionIndex(); |
| 113 if (!data()->code()->GetInstructionBlock(first_instr)->IsDeferred()) { |
| 114 SplinterLiveRange(range, data()); |
| 115 } |
| 133 } | 116 } |
| 134 } | 117 } |
| 135 | 118 |
| 136 | 119 |
| 137 void LiveRangeMerger::Merge() { | 120 void LiveRangeMerger::Merge() { |
| 138 int live_range_count = static_cast<int>(data()->live_ranges().size()); | 121 int live_range_count = static_cast<int>(data()->live_ranges().size()); |
| 139 for (int i = 0; i < live_range_count; ++i) { | 122 for (int i = 0; i < live_range_count; ++i) { |
| 140 TopLevelLiveRange *range = data()->live_ranges()[i]; | 123 TopLevelLiveRange *range = data()->live_ranges()[i]; |
| 141 if (range == nullptr || range->IsEmpty() || !range->IsSplinter()) { | 124 if (range == nullptr || range->IsEmpty() || !range->IsSplinter()) { |
| 142 continue; | 125 continue; |
| 143 } | 126 } |
| 144 TopLevelLiveRange *splinter_parent = range->splintered_from(); | 127 TopLevelLiveRange *splinter_parent = range->splintered_from(); |
| 145 | 128 |
| 146 int to_remove = range->vreg(); | 129 int to_remove = range->vreg(); |
| 147 splinter_parent->Merge(range, data()->allocation_zone()); | 130 splinter_parent->Merge(range, data()->allocation_zone()); |
| 148 data()->live_ranges()[to_remove] = nullptr; | 131 data()->live_ranges()[to_remove] = nullptr; |
| 149 } | 132 } |
| 150 } | 133 } |
| 151 | 134 |
| 152 | 135 |
| 153 } // namespace compiler | 136 } // namespace compiler |
| 154 } // namespace internal | 137 } // namespace internal |
| 155 } // namespace v8 | 138 } // namespace v8 |
| OLD | NEW |