Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "ssa_liveness_analysis.h" |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 18 | |
Ian Rogers | e77493c | 2014-08-20 15:08:45 -0700 | [diff] [blame] | 19 | #include "base/bit_vector-inl.h" |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 20 | #include "code_generator.h" |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 21 | #include "nodes.h" |
| 22 | |
| 23 | namespace art { |
| 24 | |
| 25 | void SsaLivenessAnalysis::Analyze() { |
Nicolas Geoffray | 0d3f578 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 26 | LinearizeGraph(); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 27 | NumberInstructions(); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 28 | ComputeLiveness(); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 29 | } |
| 30 | |
Nicolas Geoffray | 0d3f578 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 31 | static bool IsLoop(HLoopInformation* info) { |
| 32 | return info != nullptr; |
| 33 | } |
| 34 | |
| 35 | static bool InSameLoop(HLoopInformation* first_loop, HLoopInformation* second_loop) { |
| 36 | return first_loop == second_loop; |
| 37 | } |
| 38 | |
| 39 | static bool IsInnerLoop(HLoopInformation* outer, HLoopInformation* inner) { |
| 40 | return (inner != outer) |
| 41 | && (inner != nullptr) |
| 42 | && (outer != nullptr) |
| 43 | && inner->IsIn(*outer); |
| 44 | } |
| 45 | |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 46 | static void AddToListForLinearization(ArenaVector<HBasicBlock*>* worklist, HBasicBlock* block) { |
Nicolas Geoffray | a8eed3a | 2014-11-24 17:47:10 +0000 | [diff] [blame] | 47 | HLoopInformation* block_loop = block->GetLoopInformation(); |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 48 | auto insert_pos = worklist->rbegin(); // insert_pos.base() will be the actual position. |
| 49 | for (auto end = worklist->rend(); insert_pos != end; ++insert_pos) { |
| 50 | HBasicBlock* current = *insert_pos; |
Nicolas Geoffray | a8eed3a | 2014-11-24 17:47:10 +0000 | [diff] [blame] | 51 | HLoopInformation* current_loop = current->GetLoopInformation(); |
| 52 | if (InSameLoop(block_loop, current_loop) |
| 53 | || !IsLoop(current_loop) |
| 54 | || IsInnerLoop(current_loop, block_loop)) { |
| 55 | // The block can be processed immediately. |
| 56 | break; |
Nicolas Geoffray | e50fa58 | 2014-11-24 17:44:15 +0000 | [diff] [blame] | 57 | } |
Nicolas Geoffray | e50fa58 | 2014-11-24 17:44:15 +0000 | [diff] [blame] | 58 | } |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 59 | worklist->insert(insert_pos.base(), block); |
Nicolas Geoffray | 0d3f578 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 60 | } |
| 61 | |
Nicolas Geoffray | 0d3f578 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 62 | void SsaLivenessAnalysis::LinearizeGraph() { |
Nicolas Geoffray | a8eed3a | 2014-11-24 17:47:10 +0000 | [diff] [blame] | 63 | // Create a reverse post ordering with the following properties: |
| 64 | // - Blocks in a loop are consecutive, |
| 65 | // - Back-edge is the last block before loop exits. |
| 66 | |
| 67 | // (1): Record the number of forward predecessors for each block. This is to |
| 68 | // ensure the resulting order is reverse post order. We could use the |
| 69 | // current reverse post order in the graph, but it would require making |
| 70 | // order queries to a GrowableArray, which is not the best data structure |
| 71 | // for it. |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 72 | ArenaVector<uint32_t> forward_predecessors(graph_->GetBlocks().size(), |
| 73 | graph_->GetArena()->Adapter(kArenaAllocSsaLiveness)); |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 74 | for (HReversePostOrderIterator it(*graph_); !it.Done(); it.Advance()) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 75 | HBasicBlock* block = it.Current(); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 76 | size_t number_of_forward_predecessors = block->GetPredecessors().size(); |
Nicolas Geoffray | a8eed3a | 2014-11-24 17:47:10 +0000 | [diff] [blame] | 77 | if (block->IsLoopHeader()) { |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 78 | number_of_forward_predecessors -= block->GetLoopInformation()->NumberOfBackEdges(); |
Nicolas Geoffray | a8eed3a | 2014-11-24 17:47:10 +0000 | [diff] [blame] | 79 | } |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 80 | forward_predecessors[block->GetBlockId()] = number_of_forward_predecessors; |
Nicolas Geoffray | a8eed3a | 2014-11-24 17:47:10 +0000 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | // (2): Following a worklist approach, first start with the entry block, and |
| 84 | // iterate over the successors. When all non-back edge predecessors of a |
| 85 | // successor block are visited, the successor block is added in the worklist |
| 86 | // following an order that satisfies the requirements to build our linear graph. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 87 | graph_->linear_order_.reserve(graph_->GetReversePostOrder().size()); |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 88 | ArenaVector<HBasicBlock*> worklist(graph_->GetArena()->Adapter(kArenaAllocSsaLiveness)); |
| 89 | worklist.push_back(graph_->GetEntryBlock()); |
Nicolas Geoffray | a8eed3a | 2014-11-24 17:47:10 +0000 | [diff] [blame] | 90 | do { |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 91 | HBasicBlock* current = worklist.back(); |
| 92 | worklist.pop_back(); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 93 | graph_->linear_order_.push_back(current); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 94 | for (HBasicBlock* successor : current->GetSuccessors()) { |
Nicolas Geoffray | a8eed3a | 2014-11-24 17:47:10 +0000 | [diff] [blame] | 95 | int block_id = successor->GetBlockId(); |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 96 | size_t number_of_remaining_predecessors = forward_predecessors[block_id]; |
Nicolas Geoffray | a8eed3a | 2014-11-24 17:47:10 +0000 | [diff] [blame] | 97 | if (number_of_remaining_predecessors == 1) { |
| 98 | AddToListForLinearization(&worklist, successor); |
| 99 | } |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 100 | forward_predecessors[block_id] = number_of_remaining_predecessors - 1; |
Nicolas Geoffray | a8eed3a | 2014-11-24 17:47:10 +0000 | [diff] [blame] | 101 | } |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 102 | } while (!worklist.empty()); |
Nicolas Geoffray | 0d3f578 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 103 | } |
| 104 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 105 | void SsaLivenessAnalysis::NumberInstructions() { |
| 106 | int ssa_index = 0; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 107 | size_t lifetime_position = 0; |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 108 | // Each instruction gets a lifetime position, and a block gets a lifetime |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 109 | // start and end position. Non-phi instructions have a distinct lifetime position than |
| 110 | // the block they are in. Phi instructions have the lifetime start of their block as |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 111 | // lifetime position. |
| 112 | // |
| 113 | // Because the register allocator will insert moves in the graph, we need |
| 114 | // to differentiate between the start and end of an instruction. Adding 2 to |
| 115 | // the lifetime position for each instruction ensures the start of an |
| 116 | // instruction is different than the end of the previous instruction. |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 117 | for (HLinearOrderIterator it(*graph_); !it.Done(); it.Advance()) { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 118 | HBasicBlock* block = it.Current(); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 119 | block->SetLifetimeStart(lifetime_position); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 120 | |
Andreas Gampe | 277ccbd | 2014-11-03 21:36:10 -0800 | [diff] [blame] | 121 | for (HInstructionIterator inst_it(block->GetPhis()); !inst_it.Done(); inst_it.Advance()) { |
| 122 | HInstruction* current = inst_it.Current(); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 123 | codegen_->AllocateLocations(current); |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 124 | LocationSummary* locations = current->GetLocations(); |
| 125 | if (locations != nullptr && locations->Out().IsValid()) { |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 126 | instructions_from_ssa_index_.push_back(current); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 127 | current->SetSsaIndex(ssa_index++); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 128 | current->SetLiveInterval( |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 129 | LiveInterval::MakeInterval(graph_->GetArena(), current->GetType(), current)); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 130 | } |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 131 | current->SetLifetimePosition(lifetime_position); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 132 | } |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 133 | lifetime_position += 2; |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 134 | |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 135 | // Add a null marker to notify we are starting a block. |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 136 | instructions_from_lifetime_position_.push_back(nullptr); |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 137 | |
Andreas Gampe | 277ccbd | 2014-11-03 21:36:10 -0800 | [diff] [blame] | 138 | for (HInstructionIterator inst_it(block->GetInstructions()); !inst_it.Done(); |
| 139 | inst_it.Advance()) { |
| 140 | HInstruction* current = inst_it.Current(); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 141 | codegen_->AllocateLocations(current); |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 142 | LocationSummary* locations = current->GetLocations(); |
| 143 | if (locations != nullptr && locations->Out().IsValid()) { |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 144 | instructions_from_ssa_index_.push_back(current); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 145 | current->SetSsaIndex(ssa_index++); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 146 | current->SetLiveInterval( |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 147 | LiveInterval::MakeInterval(graph_->GetArena(), current->GetType(), current)); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 148 | } |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 149 | instructions_from_lifetime_position_.push_back(current); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 150 | current->SetLifetimePosition(lifetime_position); |
| 151 | lifetime_position += 2; |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 152 | } |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 153 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 154 | block->SetLifetimeEnd(lifetime_position); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 155 | } |
| 156 | number_of_ssa_values_ = ssa_index; |
| 157 | } |
| 158 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 159 | void SsaLivenessAnalysis::ComputeLiveness() { |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 160 | for (HLinearOrderIterator it(*graph_); !it.Done(); it.Advance()) { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 161 | HBasicBlock* block = it.Current(); |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 162 | block_infos_[block->GetBlockId()] = |
| 163 | new (graph_->GetArena()) BlockInfo(graph_->GetArena(), *block, number_of_ssa_values_); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 164 | } |
| 165 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 166 | // Compute the live ranges, as well as the initial live_in, live_out, and kill sets. |
| 167 | // This method does not handle backward branches for the sets, therefore live_in |
| 168 | // and live_out sets are not yet correct. |
| 169 | ComputeLiveRanges(); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 170 | |
| 171 | // Do a fixed point calculation to take into account backward branches, |
| 172 | // that will update live_in of loop headers, and therefore live_out and live_in |
| 173 | // of blocks in the loop. |
| 174 | ComputeLiveInAndLiveOutSets(); |
| 175 | } |
| 176 | |
David Brazdil | 674f519 | 2016-02-02 16:50:46 +0000 | [diff] [blame] | 177 | static void RecursivelyProcessInputs(HInstruction* current, |
| 178 | HInstruction* actual_user, |
| 179 | BitVector* live_in) { |
| 180 | for (size_t i = 0, e = current->InputCount(); i < e; ++i) { |
| 181 | HInstruction* input = current->InputAt(i); |
| 182 | bool has_in_location = current->GetLocations()->InAt(i).IsValid(); |
| 183 | bool has_out_location = input->GetLocations()->Out().IsValid(); |
| 184 | |
| 185 | if (has_in_location) { |
| 186 | DCHECK(has_out_location) |
| 187 | << "Instruction " << current->DebugName() << current->GetId() |
| 188 | << " expects an input value at index " << i << " but " |
| 189 | << input->DebugName() << input->GetId() << " does not produce one."; |
| 190 | DCHECK(input->HasSsaIndex()); |
| 191 | // `input` generates a result used by `current`. Add use and update |
| 192 | // the live-in set. |
| 193 | input->GetLiveInterval()->AddUse(current, /* environment */ nullptr, i, actual_user); |
| 194 | live_in->SetBit(input->GetSsaIndex()); |
| 195 | } else if (has_out_location) { |
| 196 | // `input` generates a result but it is not used by `current`. |
| 197 | } else { |
| 198 | // `input` is inlined into `current`. Walk over its inputs and record |
| 199 | // uses at `current`. |
| 200 | DCHECK(input->IsEmittedAtUseSite()); |
| 201 | // Check that the inlined input is not a phi. Recursing on loop phis could |
| 202 | // lead to an infinite loop. |
| 203 | DCHECK(!input->IsPhi()); |
| 204 | RecursivelyProcessInputs(input, actual_user, live_in); |
| 205 | } |
| 206 | } |
| 207 | } |
| 208 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 209 | void SsaLivenessAnalysis::ComputeLiveRanges() { |
| 210 | // Do a post order visit, adding inputs of instructions live in the block where |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 211 | // that instruction is defined, and killing instructions that are being visited. |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 212 | for (HLinearPostOrderIterator it(*graph_); !it.Done(); it.Advance()) { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 213 | HBasicBlock* block = it.Current(); |
| 214 | |
| 215 | BitVector* kill = GetKillSet(*block); |
| 216 | BitVector* live_in = GetLiveInSet(*block); |
| 217 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 218 | // Set phi inputs of successors of this block corresponding to this block |
| 219 | // as live_in. |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 220 | for (HBasicBlock* successor : block->GetSuccessors()) { |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 221 | live_in->Union(GetLiveInSet(*successor)); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 222 | if (successor->IsCatchBlock()) { |
| 223 | // Inputs of catch phis will be kept alive through their environment |
| 224 | // uses, allowing the runtime to copy their values to the corresponding |
| 225 | // catch phi spill slots when an exception is thrown. |
| 226 | // The only instructions which may not be recorded in the environments |
| 227 | // are constants created by the SSA builder as typed equivalents of |
| 228 | // untyped constants from the bytecode, or phis with only such constants |
| 229 | // as inputs (verified by SSAChecker). Their raw binary value must |
| 230 | // therefore be the same and we only need to keep alive one. |
| 231 | } else { |
| 232 | size_t phi_input_index = successor->GetPredecessorIndexOf(block); |
| 233 | for (HInstructionIterator phi_it(successor->GetPhis()); !phi_it.Done(); phi_it.Advance()) { |
| 234 | HInstruction* phi = phi_it.Current(); |
| 235 | HInstruction* input = phi->InputAt(phi_input_index); |
| 236 | input->GetLiveInterval()->AddPhiUse(phi, phi_input_index, block); |
| 237 | // A phi input whose last user is the phi dies at the end of the predecessor block, |
| 238 | // and not at the phi's lifetime position. |
| 239 | live_in->SetBit(input->GetSsaIndex()); |
| 240 | } |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 241 | } |
| 242 | } |
| 243 | |
| 244 | // Add a range that covers this block to all instructions live_in because of successors. |
Nicolas Geoffray | 8ddb00c | 2014-09-29 12:00:40 +0100 | [diff] [blame] | 245 | // Instructions defined in this block will have their start of the range adjusted. |
Vladimir Marko | a5b8fde | 2014-05-23 15:16:44 +0100 | [diff] [blame] | 246 | for (uint32_t idx : live_in->Indexes()) { |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 247 | HInstruction* current = GetInstructionFromSsaIndex(idx); |
Vladimir Marko | a5b8fde | 2014-05-23 15:16:44 +0100 | [diff] [blame] | 248 | current->GetLiveInterval()->AddRange(block->GetLifetimeStart(), block->GetLifetimeEnd()); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 249 | } |
| 250 | |
Andreas Gampe | 277ccbd | 2014-11-03 21:36:10 -0800 | [diff] [blame] | 251 | for (HBackwardInstructionIterator back_it(block->GetInstructions()); !back_it.Done(); |
| 252 | back_it.Advance()) { |
| 253 | HInstruction* current = back_it.Current(); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 254 | if (current->HasSsaIndex()) { |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 255 | // Kill the instruction and shorten its interval. |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 256 | kill->SetBit(current->GetSsaIndex()); |
| 257 | live_in->ClearBit(current->GetSsaIndex()); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 258 | current->GetLiveInterval()->SetFrom(current->GetLifetimePosition()); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 259 | } |
| 260 | |
Nicolas Geoffray | d8126be | 2015-03-27 10:22:41 +0000 | [diff] [blame] | 261 | // Process the environment first, because we know their uses come after |
| 262 | // or at the same liveness position of inputs. |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 263 | for (HEnvironment* environment = current->GetEnvironment(); |
| 264 | environment != nullptr; |
| 265 | environment = environment->GetParent()) { |
Nicolas Geoffray | d8126be | 2015-03-27 10:22:41 +0000 | [diff] [blame] | 266 | // Handle environment uses. See statements (b) and (c) of the |
| 267 | // SsaLivenessAnalysis. |
Nicolas Geoffray | d8126be | 2015-03-27 10:22:41 +0000 | [diff] [blame] | 268 | for (size_t i = 0, e = environment->Size(); i < e; ++i) { |
| 269 | HInstruction* instruction = environment->GetInstructionAt(i); |
Mingyao Yang | 718493c | 2015-07-22 15:56:34 -0700 | [diff] [blame] | 270 | bool should_be_live = ShouldBeLiveForEnvironment(current, instruction); |
Nicolas Geoffray | d8126be | 2015-03-27 10:22:41 +0000 | [diff] [blame] | 271 | if (should_be_live) { |
| 272 | DCHECK(instruction->HasSsaIndex()); |
| 273 | live_in->SetBit(instruction->GetSsaIndex()); |
| 274 | } |
| 275 | if (instruction != nullptr) { |
| 276 | instruction->GetLiveInterval()->AddUse( |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 277 | current, environment, i, /* actual_user */ nullptr, should_be_live); |
Nicolas Geoffray | d8126be | 2015-03-27 10:22:41 +0000 | [diff] [blame] | 278 | } |
| 279 | } |
| 280 | } |
| 281 | |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 282 | // Process inputs of instructions. |
| 283 | if (current->IsEmittedAtUseSite()) { |
| 284 | if (kIsDebugBuild) { |
| 285 | DCHECK(!current->GetLocations()->Out().IsValid()); |
| 286 | for (HUseIterator<HInstruction*> use_it(current->GetUses()); |
| 287 | !use_it.Done(); |
| 288 | use_it.Advance()) { |
| 289 | HInstruction* user = use_it.Current()->GetUser(); |
| 290 | size_t index = use_it.Current()->GetIndex(); |
| 291 | DCHECK(!user->GetLocations()->InAt(index).IsValid()); |
| 292 | } |
| 293 | DCHECK(!current->HasEnvironmentUses()); |
| 294 | } |
| 295 | } else { |
David Brazdil | 674f519 | 2016-02-02 16:50:46 +0000 | [diff] [blame] | 296 | RecursivelyProcessInputs(current, current, live_in); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 297 | } |
| 298 | } |
| 299 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 300 | // Kill phis defined in this block. |
Andreas Gampe | 277ccbd | 2014-11-03 21:36:10 -0800 | [diff] [blame] | 301 | for (HInstructionIterator inst_it(block->GetPhis()); !inst_it.Done(); inst_it.Advance()) { |
| 302 | HInstruction* current = inst_it.Current(); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 303 | if (current->HasSsaIndex()) { |
| 304 | kill->SetBit(current->GetSsaIndex()); |
| 305 | live_in->ClearBit(current->GetSsaIndex()); |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 306 | LiveInterval* interval = current->GetLiveInterval(); |
| 307 | DCHECK((interval->GetFirstRange() == nullptr) |
| 308 | || (interval->GetStart() == current->GetLifetimePosition())); |
| 309 | interval->SetFrom(current->GetLifetimePosition()); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 310 | } |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 311 | } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 312 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 313 | if (block->IsLoopHeader()) { |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 314 | if (kIsDebugBuild && block->GetLoopInformation()->IsIrreducible()) { |
| 315 | // To satisfy our liveness algorithm, we need to ensure loop headers of |
| 316 | // irreducible loops do not have any live-in instructions, except constants |
| 317 | // and the current method, which can be trivially re-materialized. |
| 318 | for (uint32_t idx : live_in->Indexes()) { |
| 319 | HInstruction* instruction = GetInstructionFromSsaIndex(idx); |
| 320 | DCHECK(instruction->GetBlock()->IsEntryBlock()) << instruction->DebugName(); |
| 321 | DCHECK(!instruction->IsParameterValue()) << instruction->DebugName(); |
| 322 | DCHECK(instruction->IsCurrentMethod() || instruction->IsConstant()) |
| 323 | << instruction->DebugName(); |
| 324 | } |
| 325 | } |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 326 | size_t last_position = block->GetLoopInformation()->GetLifetimeEnd(); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 327 | // For all live_in instructions at the loop header, we need to create a range |
| 328 | // that covers the full loop. |
Vladimir Marko | a5b8fde | 2014-05-23 15:16:44 +0100 | [diff] [blame] | 329 | for (uint32_t idx : live_in->Indexes()) { |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 330 | HInstruction* current = GetInstructionFromSsaIndex(idx); |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 331 | current->GetLiveInterval()->AddLoopRange(block->GetLifetimeStart(), last_position); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 332 | } |
| 333 | } |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | void SsaLivenessAnalysis::ComputeLiveInAndLiveOutSets() { |
| 338 | bool changed; |
| 339 | do { |
| 340 | changed = false; |
| 341 | |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 342 | for (HPostOrderIterator it(*graph_); !it.Done(); it.Advance()) { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 343 | const HBasicBlock& block = *it.Current(); |
| 344 | |
| 345 | // The live_in set depends on the kill set (which does not |
| 346 | // change in this loop), and the live_out set. If the live_out |
| 347 | // set does not change, there is no need to update the live_in set. |
| 348 | if (UpdateLiveOut(block) && UpdateLiveIn(block)) { |
| 349 | changed = true; |
| 350 | } |
| 351 | } |
| 352 | } while (changed); |
| 353 | } |
| 354 | |
| 355 | bool SsaLivenessAnalysis::UpdateLiveOut(const HBasicBlock& block) { |
| 356 | BitVector* live_out = GetLiveOutSet(block); |
| 357 | bool changed = false; |
| 358 | // The live_out set of a block is the union of live_in sets of its successors. |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 359 | for (HBasicBlock* successor : block.GetSuccessors()) { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 360 | if (live_out->Union(GetLiveInSet(*successor))) { |
| 361 | changed = true; |
| 362 | } |
| 363 | } |
| 364 | return changed; |
| 365 | } |
| 366 | |
| 367 | |
| 368 | bool SsaLivenessAnalysis::UpdateLiveIn(const HBasicBlock& block) { |
| 369 | BitVector* live_out = GetLiveOutSet(block); |
| 370 | BitVector* kill = GetKillSet(block); |
| 371 | BitVector* live_in = GetLiveInSet(block); |
| 372 | // If live_out is updated (because of backward branches), we need to make |
| 373 | // sure instructions in live_out are also in live_in, unless they are killed |
| 374 | // by this block. |
| 375 | return live_in->UnionIfNotIn(live_out, kill); |
| 376 | } |
| 377 | |
Nicolas Geoffray | da02afe | 2015-02-11 02:29:42 +0000 | [diff] [blame] | 378 | static int RegisterOrLowRegister(Location location) { |
| 379 | return location.IsPair() ? location.low() : location.reg(); |
| 380 | } |
| 381 | |
Nicolas Geoffray | fbda5f3 | 2015-04-29 14:16:00 +0100 | [diff] [blame] | 382 | int LiveInterval::FindFirstRegisterHint(size_t* free_until, |
| 383 | const SsaLivenessAnalysis& liveness) const { |
Nicolas Geoffray | da02afe | 2015-02-11 02:29:42 +0000 | [diff] [blame] | 384 | DCHECK(!IsHighInterval()); |
Nicolas Geoffray | f01d344 | 2015-03-27 17:15:49 +0000 | [diff] [blame] | 385 | if (IsTemp()) return kNoRegister; |
| 386 | |
Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 387 | if (GetParent() == this && defined_by_ != nullptr) { |
| 388 | // This is the first interval for the instruction. Try to find |
| 389 | // a register based on its definition. |
| 390 | DCHECK_EQ(defined_by_->GetLiveInterval(), this); |
| 391 | int hint = FindHintAtDefinition(); |
| 392 | if (hint != kNoRegister && free_until[hint] > GetStart()) { |
| 393 | return hint; |
| 394 | } |
| 395 | } |
| 396 | |
Nicolas Geoffray | fbda5f3 | 2015-04-29 14:16:00 +0100 | [diff] [blame] | 397 | if (IsSplit() && liveness.IsAtBlockBoundary(GetStart() / 2)) { |
| 398 | // If the start of this interval is at a block boundary, we look at the |
| 399 | // location of the interval in blocks preceding the block this interval |
| 400 | // starts at. If one location is a register we return it as a hint. This |
| 401 | // will avoid a move between the two blocks. |
| 402 | HBasicBlock* block = liveness.GetBlockFromPosition(GetStart() / 2); |
Nicolas Geoffray | 8272688 | 2015-06-01 13:51:57 +0100 | [diff] [blame] | 403 | size_t next_register_use = FirstRegisterUse(); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 404 | for (HBasicBlock* predecessor : block->GetPredecessors()) { |
| 405 | size_t position = predecessor->GetLifetimeEnd() - 1; |
Nicolas Geoffray | fbda5f3 | 2015-04-29 14:16:00 +0100 | [diff] [blame] | 406 | // We know positions above GetStart() do not have a location yet. |
| 407 | if (position < GetStart()) { |
| 408 | LiveInterval* existing = GetParent()->GetSiblingAt(position); |
| 409 | if (existing != nullptr |
| 410 | && existing->HasRegister() |
Nicolas Geoffray | 8272688 | 2015-06-01 13:51:57 +0100 | [diff] [blame] | 411 | // It's worth using that register if it is available until |
| 412 | // the next use. |
| 413 | && (free_until[existing->GetRegister()] >= next_register_use)) { |
Nicolas Geoffray | fbda5f3 | 2015-04-29 14:16:00 +0100 | [diff] [blame] | 414 | return existing->GetRegister(); |
| 415 | } |
| 416 | } |
| 417 | } |
| 418 | } |
| 419 | |
Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 420 | UsePosition* use = first_use_; |
| 421 | size_t start = GetStart(); |
| 422 | size_t end = GetEnd(); |
| 423 | while (use != nullptr && use->GetPosition() <= end) { |
| 424 | size_t use_position = use->GetPosition(); |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 425 | if (use_position >= start && !use->IsSynthesized()) { |
Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 426 | HInstruction* user = use->GetUser(); |
| 427 | size_t input_index = use->GetInputIndex(); |
| 428 | if (user->IsPhi()) { |
| 429 | // If the phi has a register, try to use the same. |
| 430 | Location phi_location = user->GetLiveInterval()->ToLocation(); |
Nicolas Geoffray | da02afe | 2015-02-11 02:29:42 +0000 | [diff] [blame] | 431 | if (phi_location.IsRegisterKind()) { |
| 432 | DCHECK(SameRegisterKind(phi_location)); |
| 433 | int reg = RegisterOrLowRegister(phi_location); |
| 434 | if (free_until[reg] >= use_position) { |
| 435 | return reg; |
| 436 | } |
Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 437 | } |
Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 438 | // If the instruction dies at the phi assignment, we can try having the |
| 439 | // same register. |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 440 | if (end == user->GetBlock()->GetPredecessors()[input_index]->GetLifetimeEnd()) { |
Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 441 | for (size_t i = 0, e = user->InputCount(); i < e; ++i) { |
| 442 | if (i == input_index) { |
| 443 | continue; |
| 444 | } |
| 445 | HInstruction* input = user->InputAt(i); |
| 446 | Location location = input->GetLiveInterval()->GetLocationAt( |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 447 | user->GetBlock()->GetPredecessors()[i]->GetLifetimeEnd() - 1); |
Nicolas Geoffray | da02afe | 2015-02-11 02:29:42 +0000 | [diff] [blame] | 448 | if (location.IsRegisterKind()) { |
| 449 | int reg = RegisterOrLowRegister(location); |
| 450 | if (free_until[reg] >= use_position) { |
| 451 | return reg; |
| 452 | } |
Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 453 | } |
| 454 | } |
| 455 | } |
| 456 | } else { |
| 457 | // If the instruction is expected in a register, try to use it. |
| 458 | LocationSummary* locations = user->GetLocations(); |
| 459 | Location expected = locations->InAt(use->GetInputIndex()); |
| 460 | // We use the user's lifetime position - 1 (and not `use_position`) because the |
| 461 | // register is blocked at the beginning of the user. |
| 462 | size_t position = user->GetLifetimePosition() - 1; |
Nicolas Geoffray | da02afe | 2015-02-11 02:29:42 +0000 | [diff] [blame] | 463 | if (expected.IsRegisterKind()) { |
| 464 | DCHECK(SameRegisterKind(expected)); |
| 465 | int reg = RegisterOrLowRegister(expected); |
| 466 | if (free_until[reg] >= position) { |
| 467 | return reg; |
| 468 | } |
Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 469 | } |
| 470 | } |
| 471 | } |
| 472 | use = use->GetNext(); |
| 473 | } |
| 474 | |
| 475 | return kNoRegister; |
| 476 | } |
| 477 | |
| 478 | int LiveInterval::FindHintAtDefinition() const { |
| 479 | if (defined_by_->IsPhi()) { |
| 480 | // Try to use the same register as one of the inputs. |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 481 | const ArenaVector<HBasicBlock*>& predecessors = defined_by_->GetBlock()->GetPredecessors(); |
Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 482 | for (size_t i = 0, e = defined_by_->InputCount(); i < e; ++i) { |
| 483 | HInstruction* input = defined_by_->InputAt(i); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 484 | size_t end = predecessors[i]->GetLifetimeEnd(); |
David Brazdil | 241a486 | 2015-04-16 17:59:03 +0100 | [diff] [blame] | 485 | LiveInterval* input_interval = input->GetLiveInterval()->GetSiblingAt(end - 1); |
| 486 | if (input_interval->GetEnd() == end) { |
Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 487 | // If the input dies at the end of the predecessor, we know its register can |
| 488 | // be reused. |
David Brazdil | 241a486 | 2015-04-16 17:59:03 +0100 | [diff] [blame] | 489 | Location input_location = input_interval->ToLocation(); |
Nicolas Geoffray | da02afe | 2015-02-11 02:29:42 +0000 | [diff] [blame] | 490 | if (input_location.IsRegisterKind()) { |
| 491 | DCHECK(SameRegisterKind(input_location)); |
| 492 | return RegisterOrLowRegister(input_location); |
Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 493 | } |
| 494 | } |
| 495 | } |
| 496 | } else { |
| 497 | LocationSummary* locations = GetDefinedBy()->GetLocations(); |
| 498 | Location out = locations->Out(); |
| 499 | if (out.IsUnallocated() && out.GetPolicy() == Location::kSameAsFirstInput) { |
| 500 | // Try to use the same register as the first input. |
David Brazdil | 241a486 | 2015-04-16 17:59:03 +0100 | [diff] [blame] | 501 | LiveInterval* input_interval = |
| 502 | GetDefinedBy()->InputAt(0)->GetLiveInterval()->GetSiblingAt(GetStart() - 1); |
| 503 | if (input_interval->GetEnd() == GetStart()) { |
Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 504 | // If the input dies at the start of this instruction, we know its register can |
| 505 | // be reused. |
David Brazdil | 241a486 | 2015-04-16 17:59:03 +0100 | [diff] [blame] | 506 | Location location = input_interval->ToLocation(); |
Nicolas Geoffray | da02afe | 2015-02-11 02:29:42 +0000 | [diff] [blame] | 507 | if (location.IsRegisterKind()) { |
| 508 | DCHECK(SameRegisterKind(location)); |
| 509 | return RegisterOrLowRegister(location); |
Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 510 | } |
| 511 | } |
| 512 | } |
| 513 | } |
| 514 | return kNoRegister; |
| 515 | } |
| 516 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 517 | bool LiveInterval::SameRegisterKind(Location other) const { |
Nicolas Geoffray | da02afe | 2015-02-11 02:29:42 +0000 | [diff] [blame] | 518 | if (IsFloatingPoint()) { |
| 519 | if (IsLowInterval() || IsHighInterval()) { |
| 520 | return other.IsFpuRegisterPair(); |
| 521 | } else { |
| 522 | return other.IsFpuRegister(); |
| 523 | } |
| 524 | } else { |
| 525 | if (IsLowInterval() || IsHighInterval()) { |
| 526 | return other.IsRegisterPair(); |
| 527 | } else { |
| 528 | return other.IsRegister(); |
| 529 | } |
| 530 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 531 | } |
| 532 | |
Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 533 | bool LiveInterval::NeedsTwoSpillSlots() const { |
| 534 | return type_ == Primitive::kPrimLong || type_ == Primitive::kPrimDouble; |
| 535 | } |
| 536 | |
| 537 | Location LiveInterval::ToLocation() const { |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 538 | DCHECK(!IsHighInterval()); |
Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 539 | if (HasRegister()) { |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 540 | if (IsFloatingPoint()) { |
| 541 | if (HasHighInterval()) { |
| 542 | return Location::FpuRegisterPairLocation(GetRegister(), GetHighInterval()->GetRegister()); |
| 543 | } else { |
| 544 | return Location::FpuRegisterLocation(GetRegister()); |
| 545 | } |
| 546 | } else { |
| 547 | if (HasHighInterval()) { |
| 548 | return Location::RegisterPairLocation(GetRegister(), GetHighInterval()->GetRegister()); |
| 549 | } else { |
| 550 | return Location::RegisterLocation(GetRegister()); |
| 551 | } |
| 552 | } |
Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 553 | } else { |
| 554 | HInstruction* defined_by = GetParent()->GetDefinedBy(); |
| 555 | if (defined_by->IsConstant()) { |
| 556 | return defined_by->GetLocations()->Out(); |
| 557 | } else if (GetParent()->HasSpillSlot()) { |
| 558 | if (NeedsTwoSpillSlots()) { |
| 559 | return Location::DoubleStackSlot(GetParent()->GetSpillSlot()); |
| 560 | } else { |
| 561 | return Location::StackSlot(GetParent()->GetSpillSlot()); |
| 562 | } |
| 563 | } else { |
| 564 | return Location(); |
| 565 | } |
| 566 | } |
| 567 | } |
| 568 | |
David Brazdil | 5b8e6a5 | 2015-02-25 16:17:05 +0000 | [diff] [blame] | 569 | Location LiveInterval::GetLocationAt(size_t position) { |
David Brazdil | 241a486 | 2015-04-16 17:59:03 +0100 | [diff] [blame] | 570 | LiveInterval* sibling = GetSiblingAt(position); |
| 571 | DCHECK(sibling != nullptr); |
| 572 | return sibling->ToLocation(); |
Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 573 | } |
| 574 | |
David Brazdil | 241a486 | 2015-04-16 17:59:03 +0100 | [diff] [blame] | 575 | LiveInterval* LiveInterval::GetSiblingAt(size_t position) { |
David Brazdil | 5b8e6a5 | 2015-02-25 16:17:05 +0000 | [diff] [blame] | 576 | LiveInterval* current = this; |
David Brazdil | 241a486 | 2015-04-16 17:59:03 +0100 | [diff] [blame] | 577 | while (current != nullptr && !current->IsDefinedAt(position)) { |
Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 578 | current = current->GetNextSibling(); |
Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 579 | } |
David Brazdil | 241a486 | 2015-04-16 17:59:03 +0100 | [diff] [blame] | 580 | return current; |
Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 581 | } |
| 582 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 583 | } // namespace art |