| 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" | 
| Aart Bik | 9620230 | 2016-10-04 17:33:56 -0700 | [diff] [blame] | 21 | #include "linear_order.h" | 
| Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 22 | #include "nodes.h" | 
 | 23 |  | 
 | 24 | namespace art { | 
 | 25 |  | 
 | 26 | void SsaLivenessAnalysis::Analyze() { | 
| Aart Bik | 9620230 | 2016-10-04 17:33:56 -0700 | [diff] [blame] | 27 |   // Compute the linear order directly in the graph's data structure | 
 | 28 |   // (there are no more following graph mutations). | 
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 29 |   LinearizeGraph(graph_, &graph_->linear_order_); | 
| Aart Bik | 9620230 | 2016-10-04 17:33:56 -0700 | [diff] [blame] | 30 |  | 
 | 31 |   // Liveness analysis. | 
| Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 32 |   NumberInstructions(); | 
| Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 33 |   ComputeLiveness(); | 
| Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 34 | } | 
 | 35 |  | 
 | 36 | void SsaLivenessAnalysis::NumberInstructions() { | 
 | 37 |   int ssa_index = 0; | 
| Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 38 |   size_t lifetime_position = 0; | 
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 39 |   // Each instruction gets a lifetime position, and a block gets a lifetime | 
| Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 40 |   // start and end position. Non-phi instructions have a distinct lifetime position than | 
 | 41 |   // 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] | 42 |   // lifetime position. | 
 | 43 |   // | 
 | 44 |   // Because the register allocator will insert moves in the graph, we need | 
 | 45 |   // to differentiate between the start and end of an instruction. Adding 2 to | 
 | 46 |   // the lifetime position for each instruction ensures the start of an | 
 | 47 |   // instruction is different than the end of the previous instruction. | 
| Aart Bik | 9620230 | 2016-10-04 17:33:56 -0700 | [diff] [blame] | 48 |   for (HBasicBlock* block : graph_->GetLinearOrder()) { | 
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 49 |     block->SetLifetimeStart(lifetime_position); | 
| Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 50 |  | 
| Andreas Gampe | 277ccbd | 2014-11-03 21:36:10 -0800 | [diff] [blame] | 51 |     for (HInstructionIterator inst_it(block->GetPhis()); !inst_it.Done(); inst_it.Advance()) { | 
 | 52 |       HInstruction* current = inst_it.Current(); | 
| Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 53 |       codegen_->AllocateLocations(current); | 
| Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 54 |       LocationSummary* locations = current->GetLocations(); | 
 | 55 |       if (locations != nullptr && locations->Out().IsValid()) { | 
| Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 56 |         instructions_from_ssa_index_.push_back(current); | 
| Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 57 |         current->SetSsaIndex(ssa_index++); | 
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 58 |         current->SetLiveInterval( | 
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 59 |             LiveInterval::MakeInterval(allocator_, current->GetType(), current)); | 
| Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 60 |       } | 
| Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 61 |       current->SetLifetimePosition(lifetime_position); | 
| Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 62 |     } | 
| Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 63 |     lifetime_position += 2; | 
| Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 64 |  | 
| Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 65 |     // Add a null marker to notify we are starting a block. | 
| Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 66 |     instructions_from_lifetime_position_.push_back(nullptr); | 
| Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 67 |  | 
| Andreas Gampe | 277ccbd | 2014-11-03 21:36:10 -0800 | [diff] [blame] | 68 |     for (HInstructionIterator inst_it(block->GetInstructions()); !inst_it.Done(); | 
 | 69 |          inst_it.Advance()) { | 
 | 70 |       HInstruction* current = inst_it.Current(); | 
| Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 71 |       codegen_->AllocateLocations(current); | 
| Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 72 |       LocationSummary* locations = current->GetLocations(); | 
 | 73 |       if (locations != nullptr && locations->Out().IsValid()) { | 
| Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 74 |         instructions_from_ssa_index_.push_back(current); | 
| Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 75 |         current->SetSsaIndex(ssa_index++); | 
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 76 |         current->SetLiveInterval( | 
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 77 |             LiveInterval::MakeInterval(allocator_, current->GetType(), current)); | 
| Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 78 |       } | 
| Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 79 |       instructions_from_lifetime_position_.push_back(current); | 
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 80 |       current->SetLifetimePosition(lifetime_position); | 
 | 81 |       lifetime_position += 2; | 
| Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 82 |     } | 
| Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 83 |  | 
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 84 |     block->SetLifetimeEnd(lifetime_position); | 
| Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 85 |   } | 
 | 86 |   number_of_ssa_values_ = ssa_index; | 
 | 87 | } | 
 | 88 |  | 
| Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 89 | void SsaLivenessAnalysis::ComputeLiveness() { | 
| Aart Bik | 9620230 | 2016-10-04 17:33:56 -0700 | [diff] [blame] | 90 |   for (HBasicBlock* block : graph_->GetLinearOrder()) { | 
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 91 |     block_infos_[block->GetBlockId()] = | 
 | 92 |         new (allocator_) BlockInfo(allocator_, *block, number_of_ssa_values_); | 
| Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 93 |   } | 
 | 94 |  | 
| Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 95 |   // Compute the live ranges, as well as the initial live_in, live_out, and kill sets. | 
 | 96 |   // This method does not handle backward branches for the sets, therefore live_in | 
 | 97 |   // and live_out sets are not yet correct. | 
 | 98 |   ComputeLiveRanges(); | 
| Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 99 |  | 
 | 100 |   // Do a fixed point calculation to take into account backward branches, | 
 | 101 |   // that will update live_in of loop headers, and therefore live_out and live_in | 
 | 102 |   // of blocks in the loop. | 
 | 103 |   ComputeLiveInAndLiveOutSets(); | 
 | 104 | } | 
 | 105 |  | 
| David Brazdil | 674f519 | 2016-02-02 16:50:46 +0000 | [diff] [blame] | 106 | static void RecursivelyProcessInputs(HInstruction* current, | 
 | 107 |                                      HInstruction* actual_user, | 
 | 108 |                                      BitVector* live_in) { | 
| Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 109 |   HInputsRef inputs = current->GetInputs(); | 
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 110 |   for (size_t i = 0; i < inputs.size(); ++i) { | 
 | 111 |     HInstruction* input = inputs[i]; | 
| David Brazdil | 674f519 | 2016-02-02 16:50:46 +0000 | [diff] [blame] | 112 |     bool has_in_location = current->GetLocations()->InAt(i).IsValid(); | 
 | 113 |     bool has_out_location = input->GetLocations()->Out().IsValid(); | 
 | 114 |  | 
 | 115 |     if (has_in_location) { | 
 | 116 |       DCHECK(has_out_location) | 
 | 117 |           << "Instruction " << current->DebugName() << current->GetId() | 
 | 118 |           << " expects an input value at index " << i << " but " | 
 | 119 |           << input->DebugName() << input->GetId() << " does not produce one."; | 
 | 120 |       DCHECK(input->HasSsaIndex()); | 
 | 121 |       // `input` generates a result used by `current`. Add use and update | 
 | 122 |       // the live-in set. | 
 | 123 |       input->GetLiveInterval()->AddUse(current, /* environment */ nullptr, i, actual_user); | 
 | 124 |       live_in->SetBit(input->GetSsaIndex()); | 
 | 125 |     } else if (has_out_location) { | 
 | 126 |       // `input` generates a result but it is not used by `current`. | 
 | 127 |     } else { | 
 | 128 |       // `input` is inlined into `current`. Walk over its inputs and record | 
 | 129 |       // uses at `current`. | 
 | 130 |       DCHECK(input->IsEmittedAtUseSite()); | 
 | 131 |       // Check that the inlined input is not a phi. Recursing on loop phis could | 
 | 132 |       // lead to an infinite loop. | 
 | 133 |       DCHECK(!input->IsPhi()); | 
 | 134 |       RecursivelyProcessInputs(input, actual_user, live_in); | 
 | 135 |     } | 
 | 136 |   } | 
 | 137 | } | 
 | 138 |  | 
| Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 139 | void SsaLivenessAnalysis::ComputeLiveRanges() { | 
 | 140 |   // 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] | 141 |   // that instruction is defined, and killing instructions that are being visited. | 
| Vladimir Marko | 2c45bc9 | 2016-10-25 16:54:12 +0100 | [diff] [blame] | 142 |   for (HBasicBlock* block : ReverseRange(graph_->GetLinearOrder())) { | 
| Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 143 |     BitVector* kill = GetKillSet(*block); | 
 | 144 |     BitVector* live_in = GetLiveInSet(*block); | 
 | 145 |  | 
| Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 146 |     // Set phi inputs of successors of this block corresponding to this block | 
 | 147 |     // as live_in. | 
| Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 148 |     for (HBasicBlock* successor : block->GetSuccessors()) { | 
| Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 149 |       live_in->Union(GetLiveInSet(*successor)); | 
| David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 150 |       if (successor->IsCatchBlock()) { | 
 | 151 |         // Inputs of catch phis will be kept alive through their environment | 
 | 152 |         // uses, allowing the runtime to copy their values to the corresponding | 
 | 153 |         // catch phi spill slots when an exception is thrown. | 
 | 154 |         // The only instructions which may not be recorded in the environments | 
 | 155 |         // are constants created by the SSA builder as typed equivalents of | 
 | 156 |         // untyped constants from the bytecode, or phis with only such constants | 
| David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 157 |         // as inputs (verified by GraphChecker). Their raw binary value must | 
| David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 158 |         // therefore be the same and we only need to keep alive one. | 
 | 159 |       } else { | 
 | 160 |         size_t phi_input_index = successor->GetPredecessorIndexOf(block); | 
 | 161 |         for (HInstructionIterator phi_it(successor->GetPhis()); !phi_it.Done(); phi_it.Advance()) { | 
 | 162 |           HInstruction* phi = phi_it.Current(); | 
 | 163 |           HInstruction* input = phi->InputAt(phi_input_index); | 
 | 164 |           input->GetLiveInterval()->AddPhiUse(phi, phi_input_index, block); | 
 | 165 |           // A phi input whose last user is the phi dies at the end of the predecessor block, | 
 | 166 |           // and not at the phi's lifetime position. | 
 | 167 |           live_in->SetBit(input->GetSsaIndex()); | 
 | 168 |         } | 
| Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 169 |       } | 
 | 170 |     } | 
 | 171 |  | 
 | 172 |     // 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] | 173 |     // 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] | 174 |     for (uint32_t idx : live_in->Indexes()) { | 
| Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 175 |       HInstruction* current = GetInstructionFromSsaIndex(idx); | 
| Vladimir Marko | a5b8fde | 2014-05-23 15:16:44 +0100 | [diff] [blame] | 176 |       current->GetLiveInterval()->AddRange(block->GetLifetimeStart(), block->GetLifetimeEnd()); | 
| Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 177 |     } | 
 | 178 |  | 
| Andreas Gampe | 277ccbd | 2014-11-03 21:36:10 -0800 | [diff] [blame] | 179 |     for (HBackwardInstructionIterator back_it(block->GetInstructions()); !back_it.Done(); | 
 | 180 |          back_it.Advance()) { | 
 | 181 |       HInstruction* current = back_it.Current(); | 
| Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 182 |       if (current->HasSsaIndex()) { | 
| Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 183 |         // Kill the instruction and shorten its interval. | 
| Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 184 |         kill->SetBit(current->GetSsaIndex()); | 
 | 185 |         live_in->ClearBit(current->GetSsaIndex()); | 
| Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 186 |         current->GetLiveInterval()->SetFrom(current->GetLifetimePosition()); | 
| Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 187 |       } | 
 | 188 |  | 
| Nicolas Geoffray | d8126be | 2015-03-27 10:22:41 +0000 | [diff] [blame] | 189 |       // Process the environment first, because we know their uses come after | 
 | 190 |       // or at the same liveness position of inputs. | 
| Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 191 |       for (HEnvironment* environment = current->GetEnvironment(); | 
 | 192 |            environment != nullptr; | 
 | 193 |            environment = environment->GetParent()) { | 
| Nicolas Geoffray | d8126be | 2015-03-27 10:22:41 +0000 | [diff] [blame] | 194 |         // Handle environment uses. See statements (b) and (c) of the | 
 | 195 |         // SsaLivenessAnalysis. | 
| Nicolas Geoffray | d8126be | 2015-03-27 10:22:41 +0000 | [diff] [blame] | 196 |         for (size_t i = 0, e = environment->Size(); i < e; ++i) { | 
 | 197 |           HInstruction* instruction = environment->GetInstructionAt(i); | 
| Artem Serov | d675053 | 2018-05-30 20:07:43 +0100 | [diff] [blame] | 198 |           if (instruction == nullptr) { | 
 | 199 |             continue; | 
 | 200 |           } | 
| Mingyao Yang | 718493c | 2015-07-22 15:56:34 -0700 | [diff] [blame] | 201 |           bool should_be_live = ShouldBeLiveForEnvironment(current, instruction); | 
| Artem Serov | d675053 | 2018-05-30 20:07:43 +0100 | [diff] [blame] | 202 |           // If this environment use does not keep the instruction live, it does not | 
 | 203 |           // affect the live range of that instruction. | 
| Nicolas Geoffray | d8126be | 2015-03-27 10:22:41 +0000 | [diff] [blame] | 204 |           if (should_be_live) { | 
| Nicolas Geoffray | c9c3104 | 2017-06-29 14:04:16 +0100 | [diff] [blame] | 205 |             CHECK(instruction->HasSsaIndex()) << instruction->DebugName(); | 
| Nicolas Geoffray | d8126be | 2015-03-27 10:22:41 +0000 | [diff] [blame] | 206 |             live_in->SetBit(instruction->GetSsaIndex()); | 
| Artem Serov | d675053 | 2018-05-30 20:07:43 +0100 | [diff] [blame] | 207 |             instruction->GetLiveInterval()->AddUse(current, | 
 | 208 |                                                    environment, | 
 | 209 |                                                    i, | 
 | 210 |                                                    /* actual_user */ nullptr); | 
| Nicolas Geoffray | d8126be | 2015-03-27 10:22:41 +0000 | [diff] [blame] | 211 |           } | 
 | 212 |         } | 
 | 213 |       } | 
 | 214 |  | 
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 215 |       // Process inputs of instructions. | 
 | 216 |       if (current->IsEmittedAtUseSite()) { | 
 | 217 |         if (kIsDebugBuild) { | 
 | 218 |           DCHECK(!current->GetLocations()->Out().IsValid()); | 
| Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 219 |           for (const HUseListNode<HInstruction*>& use : current->GetUses()) { | 
 | 220 |             HInstruction* user = use.GetUser(); | 
 | 221 |             size_t index = use.GetIndex(); | 
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 222 |             DCHECK(!user->GetLocations()->InAt(index).IsValid()); | 
 | 223 |           } | 
 | 224 |           DCHECK(!current->HasEnvironmentUses()); | 
 | 225 |         } | 
 | 226 |       } else { | 
| David Brazdil | 674f519 | 2016-02-02 16:50:46 +0000 | [diff] [blame] | 227 |         RecursivelyProcessInputs(current, current, live_in); | 
| Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 228 |       } | 
 | 229 |     } | 
 | 230 |  | 
| Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 231 |     // Kill phis defined in this block. | 
| Andreas Gampe | 277ccbd | 2014-11-03 21:36:10 -0800 | [diff] [blame] | 232 |     for (HInstructionIterator inst_it(block->GetPhis()); !inst_it.Done(); inst_it.Advance()) { | 
 | 233 |       HInstruction* current = inst_it.Current(); | 
| Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 234 |       if (current->HasSsaIndex()) { | 
 | 235 |         kill->SetBit(current->GetSsaIndex()); | 
 | 236 |         live_in->ClearBit(current->GetSsaIndex()); | 
| Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 237 |         LiveInterval* interval = current->GetLiveInterval(); | 
 | 238 |         DCHECK((interval->GetFirstRange() == nullptr) | 
 | 239 |                || (interval->GetStart() == current->GetLifetimePosition())); | 
 | 240 |         interval->SetFrom(current->GetLifetimePosition()); | 
| Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 241 |       } | 
| Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 242 |     } | 
| Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 243 |  | 
| Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 244 |     if (block->IsLoopHeader()) { | 
| Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 245 |       if (kIsDebugBuild) { | 
 | 246 |         CheckNoLiveInIrreducibleLoop(*block); | 
| Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 247 |       } | 
| Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 248 |       size_t last_position = block->GetLoopInformation()->GetLifetimeEnd(); | 
| Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 249 |       // For all live_in instructions at the loop header, we need to create a range | 
 | 250 |       // that covers the full loop. | 
| Vladimir Marko | a5b8fde | 2014-05-23 15:16:44 +0100 | [diff] [blame] | 251 |       for (uint32_t idx : live_in->Indexes()) { | 
| Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 252 |         HInstruction* current = GetInstructionFromSsaIndex(idx); | 
| Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 253 |         current->GetLiveInterval()->AddLoopRange(block->GetLifetimeStart(), last_position); | 
| Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 254 |       } | 
 | 255 |     } | 
 | 256 |   } | 
 | 257 | } | 
 | 258 |  | 
 | 259 | void SsaLivenessAnalysis::ComputeLiveInAndLiveOutSets() { | 
 | 260 |   bool changed; | 
 | 261 |   do { | 
 | 262 |     changed = false; | 
 | 263 |  | 
| Vladimir Marko | 2c45bc9 | 2016-10-25 16:54:12 +0100 | [diff] [blame] | 264 |     for (const HBasicBlock* block : graph_->GetPostOrder()) { | 
| Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 265 |       // The live_in set depends on the kill set (which does not | 
 | 266 |       // change in this loop), and the live_out set.  If the live_out | 
 | 267 |       // set does not change, there is no need to update the live_in set. | 
| Vladimir Marko | 2c45bc9 | 2016-10-25 16:54:12 +0100 | [diff] [blame] | 268 |       if (UpdateLiveOut(*block) && UpdateLiveIn(*block)) { | 
| Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 269 |         if (kIsDebugBuild) { | 
| Vladimir Marko | 2c45bc9 | 2016-10-25 16:54:12 +0100 | [diff] [blame] | 270 |           CheckNoLiveInIrreducibleLoop(*block); | 
| Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 271 |         } | 
| Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 272 |         changed = true; | 
 | 273 |       } | 
 | 274 |     } | 
 | 275 |   } while (changed); | 
 | 276 | } | 
 | 277 |  | 
 | 278 | bool SsaLivenessAnalysis::UpdateLiveOut(const HBasicBlock& block) { | 
 | 279 |   BitVector* live_out = GetLiveOutSet(block); | 
 | 280 |   bool changed = false; | 
 | 281 |   // 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] | 282 |   for (HBasicBlock* successor : block.GetSuccessors()) { | 
| Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 283 |     if (live_out->Union(GetLiveInSet(*successor))) { | 
 | 284 |       changed = true; | 
 | 285 |     } | 
 | 286 |   } | 
 | 287 |   return changed; | 
 | 288 | } | 
 | 289 |  | 
 | 290 |  | 
 | 291 | bool SsaLivenessAnalysis::UpdateLiveIn(const HBasicBlock& block) { | 
 | 292 |   BitVector* live_out = GetLiveOutSet(block); | 
 | 293 |   BitVector* kill = GetKillSet(block); | 
 | 294 |   BitVector* live_in = GetLiveInSet(block); | 
 | 295 |   // If live_out is updated (because of backward branches), we need to make | 
 | 296 |   // sure instructions in live_out are also in live_in, unless they are killed | 
 | 297 |   // by this block. | 
 | 298 |   return live_in->UnionIfNotIn(live_out, kill); | 
 | 299 | } | 
 | 300 |  | 
| Matthew Gharrity | d9ffd0d | 2016-06-22 10:27:55 -0700 | [diff] [blame] | 301 | void LiveInterval::DumpWithContext(std::ostream& stream, | 
 | 302 |                                    const CodeGenerator& codegen) const { | 
 | 303 |   Dump(stream); | 
 | 304 |   if (IsFixed()) { | 
 | 305 |     stream << ", register:" << GetRegister() << "("; | 
 | 306 |     if (IsFloatingPoint()) { | 
 | 307 |       codegen.DumpFloatingPointRegister(stream, GetRegister()); | 
 | 308 |     } else { | 
 | 309 |       codegen.DumpCoreRegister(stream, GetRegister()); | 
 | 310 |     } | 
 | 311 |     stream << ")"; | 
 | 312 |   } else { | 
 | 313 |     stream << ", spill slot:" << GetSpillSlot(); | 
 | 314 |   } | 
 | 315 |   stream << ", requires_register:" << (GetDefinedBy() != nullptr && RequiresRegister()); | 
 | 316 |   if (GetParent()->GetDefinedBy() != nullptr) { | 
 | 317 |     stream << ", defined_by:" << GetParent()->GetDefinedBy()->GetKind(); | 
 | 318 |     stream << "(" << GetParent()->GetDefinedBy()->GetLifetimePosition() << ")"; | 
 | 319 |   } | 
 | 320 | } | 
 | 321 |  | 
| Nicolas Geoffray | da02afe | 2015-02-11 02:29:42 +0000 | [diff] [blame] | 322 | static int RegisterOrLowRegister(Location location) { | 
 | 323 |   return location.IsPair() ? location.low() : location.reg(); | 
 | 324 | } | 
 | 325 |  | 
| Nicolas Geoffray | fbda5f3 | 2015-04-29 14:16:00 +0100 | [diff] [blame] | 326 | int LiveInterval::FindFirstRegisterHint(size_t* free_until, | 
 | 327 |                                         const SsaLivenessAnalysis& liveness) const { | 
| Nicolas Geoffray | da02afe | 2015-02-11 02:29:42 +0000 | [diff] [blame] | 328 |   DCHECK(!IsHighInterval()); | 
| Nicolas Geoffray | f01d344 | 2015-03-27 17:15:49 +0000 | [diff] [blame] | 329 |   if (IsTemp()) return kNoRegister; | 
 | 330 |  | 
| Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 331 |   if (GetParent() == this && defined_by_ != nullptr) { | 
 | 332 |     // This is the first interval for the instruction. Try to find | 
 | 333 |     // a register based on its definition. | 
 | 334 |     DCHECK_EQ(defined_by_->GetLiveInterval(), this); | 
 | 335 |     int hint = FindHintAtDefinition(); | 
 | 336 |     if (hint != kNoRegister && free_until[hint] > GetStart()) { | 
 | 337 |       return hint; | 
 | 338 |     } | 
 | 339 |   } | 
 | 340 |  | 
| Nicolas Geoffray | fbda5f3 | 2015-04-29 14:16:00 +0100 | [diff] [blame] | 341 |   if (IsSplit() && liveness.IsAtBlockBoundary(GetStart() / 2)) { | 
 | 342 |     // If the start of this interval is at a block boundary, we look at the | 
 | 343 |     // location of the interval in blocks preceding the block this interval | 
 | 344 |     // starts at. If one location is a register we return it as a hint. This | 
 | 345 |     // will avoid a move between the two blocks. | 
 | 346 |     HBasicBlock* block = liveness.GetBlockFromPosition(GetStart() / 2); | 
| Nicolas Geoffray | 8272688 | 2015-06-01 13:51:57 +0100 | [diff] [blame] | 347 |     size_t next_register_use = FirstRegisterUse(); | 
| Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 348 |     for (HBasicBlock* predecessor : block->GetPredecessors()) { | 
 | 349 |       size_t position = predecessor->GetLifetimeEnd() - 1; | 
| Nicolas Geoffray | fbda5f3 | 2015-04-29 14:16:00 +0100 | [diff] [blame] | 350 |       // We know positions above GetStart() do not have a location yet. | 
 | 351 |       if (position < GetStart()) { | 
 | 352 |         LiveInterval* existing = GetParent()->GetSiblingAt(position); | 
 | 353 |         if (existing != nullptr | 
 | 354 |             && existing->HasRegister() | 
| Nicolas Geoffray | 8272688 | 2015-06-01 13:51:57 +0100 | [diff] [blame] | 355 |             // It's worth using that register if it is available until | 
 | 356 |             // the next use. | 
 | 357 |             && (free_until[existing->GetRegister()] >= next_register_use)) { | 
| Nicolas Geoffray | fbda5f3 | 2015-04-29 14:16:00 +0100 | [diff] [blame] | 358 |           return existing->GetRegister(); | 
 | 359 |         } | 
 | 360 |       } | 
 | 361 |     } | 
 | 362 |   } | 
 | 363 |  | 
| Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 364 |   size_t start = GetStart(); | 
 | 365 |   size_t end = GetEnd(); | 
| Vladimir Marko | 82b0740 | 2017-03-01 19:02:04 +0000 | [diff] [blame] | 366 |   for (const UsePosition& use : GetUses()) { | 
 | 367 |     size_t use_position = use.GetPosition(); | 
 | 368 |     if (use_position > end) { | 
 | 369 |       break; | 
 | 370 |     } | 
 | 371 |     if (use_position >= start && !use.IsSynthesized()) { | 
 | 372 |       HInstruction* user = use.GetUser(); | 
 | 373 |       size_t input_index = use.GetInputIndex(); | 
| Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 374 |       if (user->IsPhi()) { | 
 | 375 |         // If the phi has a register, try to use the same. | 
 | 376 |         Location phi_location = user->GetLiveInterval()->ToLocation(); | 
| Nicolas Geoffray | da02afe | 2015-02-11 02:29:42 +0000 | [diff] [blame] | 377 |         if (phi_location.IsRegisterKind()) { | 
 | 378 |           DCHECK(SameRegisterKind(phi_location)); | 
 | 379 |           int reg = RegisterOrLowRegister(phi_location); | 
 | 380 |           if (free_until[reg] >= use_position) { | 
 | 381 |             return reg; | 
 | 382 |           } | 
| Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 383 |         } | 
| Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 384 |         // If the instruction dies at the phi assignment, we can try having the | 
 | 385 |         // same register. | 
| Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 386 |         if (end == user->GetBlock()->GetPredecessors()[input_index]->GetLifetimeEnd()) { | 
| Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 387 |           HInputsRef inputs = user->GetInputs(); | 
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 388 |           for (size_t i = 0; i < inputs.size(); ++i) { | 
| Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 389 |             if (i == input_index) { | 
 | 390 |               continue; | 
 | 391 |             } | 
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 392 |             Location location = inputs[i]->GetLiveInterval()->GetLocationAt( | 
| Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 393 |                 user->GetBlock()->GetPredecessors()[i]->GetLifetimeEnd() - 1); | 
| Nicolas Geoffray | da02afe | 2015-02-11 02:29:42 +0000 | [diff] [blame] | 394 |             if (location.IsRegisterKind()) { | 
 | 395 |               int reg = RegisterOrLowRegister(location); | 
 | 396 |               if (free_until[reg] >= use_position) { | 
 | 397 |                 return reg; | 
 | 398 |               } | 
| Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 399 |             } | 
 | 400 |           } | 
 | 401 |         } | 
 | 402 |       } else { | 
 | 403 |         // If the instruction is expected in a register, try to use it. | 
 | 404 |         LocationSummary* locations = user->GetLocations(); | 
| Vladimir Marko | 82b0740 | 2017-03-01 19:02:04 +0000 | [diff] [blame] | 405 |         Location expected = locations->InAt(use.GetInputIndex()); | 
| Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 406 |         // We use the user's lifetime position - 1 (and not `use_position`) because the | 
 | 407 |         // register is blocked at the beginning of the user. | 
 | 408 |         size_t position = user->GetLifetimePosition() - 1; | 
| Nicolas Geoffray | da02afe | 2015-02-11 02:29:42 +0000 | [diff] [blame] | 409 |         if (expected.IsRegisterKind()) { | 
 | 410 |           DCHECK(SameRegisterKind(expected)); | 
 | 411 |           int reg = RegisterOrLowRegister(expected); | 
 | 412 |           if (free_until[reg] >= position) { | 
 | 413 |             return reg; | 
 | 414 |           } | 
| Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 415 |         } | 
 | 416 |       } | 
 | 417 |     } | 
| Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 418 |   } | 
 | 419 |  | 
 | 420 |   return kNoRegister; | 
 | 421 | } | 
 | 422 |  | 
 | 423 | int LiveInterval::FindHintAtDefinition() const { | 
 | 424 |   if (defined_by_->IsPhi()) { | 
 | 425 |     // Try to use the same register as one of the inputs. | 
| Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 426 |     const ArenaVector<HBasicBlock*>& predecessors = defined_by_->GetBlock()->GetPredecessors(); | 
| Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 427 |     HInputsRef inputs = defined_by_->GetInputs(); | 
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 428 |     for (size_t i = 0; i < inputs.size(); ++i) { | 
| Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 429 |       size_t end = predecessors[i]->GetLifetimeEnd(); | 
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 430 |       LiveInterval* input_interval = inputs[i]->GetLiveInterval()->GetSiblingAt(end - 1); | 
| David Brazdil | 241a486 | 2015-04-16 17:59:03 +0100 | [diff] [blame] | 431 |       if (input_interval->GetEnd() == end) { | 
| Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 432 |         // If the input dies at the end of the predecessor, we know its register can | 
 | 433 |         // be reused. | 
| David Brazdil | 241a486 | 2015-04-16 17:59:03 +0100 | [diff] [blame] | 434 |         Location input_location = input_interval->ToLocation(); | 
| Nicolas Geoffray | da02afe | 2015-02-11 02:29:42 +0000 | [diff] [blame] | 435 |         if (input_location.IsRegisterKind()) { | 
 | 436 |           DCHECK(SameRegisterKind(input_location)); | 
 | 437 |           return RegisterOrLowRegister(input_location); | 
| Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 438 |         } | 
 | 439 |       } | 
 | 440 |     } | 
 | 441 |   } else { | 
 | 442 |     LocationSummary* locations = GetDefinedBy()->GetLocations(); | 
 | 443 |     Location out = locations->Out(); | 
 | 444 |     if (out.IsUnallocated() && out.GetPolicy() == Location::kSameAsFirstInput) { | 
 | 445 |       // Try to use the same register as the first input. | 
| David Brazdil | 241a486 | 2015-04-16 17:59:03 +0100 | [diff] [blame] | 446 |       LiveInterval* input_interval = | 
 | 447 |           GetDefinedBy()->InputAt(0)->GetLiveInterval()->GetSiblingAt(GetStart() - 1); | 
 | 448 |       if (input_interval->GetEnd() == GetStart()) { | 
| Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 449 |         // If the input dies at the start of this instruction, we know its register can | 
 | 450 |         // be reused. | 
| David Brazdil | 241a486 | 2015-04-16 17:59:03 +0100 | [diff] [blame] | 451 |         Location location = input_interval->ToLocation(); | 
| Nicolas Geoffray | da02afe | 2015-02-11 02:29:42 +0000 | [diff] [blame] | 452 |         if (location.IsRegisterKind()) { | 
 | 453 |           DCHECK(SameRegisterKind(location)); | 
 | 454 |           return RegisterOrLowRegister(location); | 
| Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 455 |         } | 
 | 456 |       } | 
 | 457 |     } | 
 | 458 |   } | 
 | 459 |   return kNoRegister; | 
 | 460 | } | 
 | 461 |  | 
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 462 | bool LiveInterval::SameRegisterKind(Location other) const { | 
| Nicolas Geoffray | da02afe | 2015-02-11 02:29:42 +0000 | [diff] [blame] | 463 |   if (IsFloatingPoint()) { | 
 | 464 |     if (IsLowInterval() || IsHighInterval()) { | 
 | 465 |       return other.IsFpuRegisterPair(); | 
 | 466 |     } else { | 
 | 467 |       return other.IsFpuRegister(); | 
 | 468 |     } | 
 | 469 |   } else { | 
 | 470 |     if (IsLowInterval() || IsHighInterval()) { | 
 | 471 |       return other.IsRegisterPair(); | 
 | 472 |     } else { | 
 | 473 |       return other.IsRegister(); | 
 | 474 |     } | 
 | 475 |   } | 
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 476 | } | 
 | 477 |  | 
| Aart Bik | cc89525 | 2017-03-21 10:55:15 -0700 | [diff] [blame] | 478 | size_t LiveInterval::NumberOfSpillSlotsNeeded() const { | 
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 479 |   // For a SIMD operation, compute the number of needed spill slots. | 
 | 480 |   // TODO: do through vector type? | 
 | 481 |   HInstruction* definition = GetParent()->GetDefinedBy(); | 
| Aart Bik | 2dd7b67 | 2017-12-07 11:11:22 -0800 | [diff] [blame] | 482 |   if (definition != nullptr && HVecOperation::ReturnsSIMDValue(definition)) { | 
 | 483 |     if (definition->IsPhi()) { | 
 | 484 |       definition = definition->InputAt(1);  // SIMD always appears on back-edge | 
 | 485 |     } | 
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 486 |     return definition->AsVecOperation()->GetVectorNumberOfBytes() / kVRegSize; | 
 | 487 |   } | 
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 488 |   // Return number of needed spill slots based on type. | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 489 |   return (type_ == DataType::Type::kInt64 || type_ == DataType::Type::kFloat64) ? 2 : 1; | 
| Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 490 | } | 
 | 491 |  | 
 | 492 | Location LiveInterval::ToLocation() const { | 
| Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 493 |   DCHECK(!IsHighInterval()); | 
| Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 494 |   if (HasRegister()) { | 
| Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 495 |     if (IsFloatingPoint()) { | 
 | 496 |       if (HasHighInterval()) { | 
 | 497 |         return Location::FpuRegisterPairLocation(GetRegister(), GetHighInterval()->GetRegister()); | 
 | 498 |       } else { | 
 | 499 |         return Location::FpuRegisterLocation(GetRegister()); | 
 | 500 |       } | 
 | 501 |     } else { | 
 | 502 |       if (HasHighInterval()) { | 
 | 503 |         return Location::RegisterPairLocation(GetRegister(), GetHighInterval()->GetRegister()); | 
 | 504 |       } else { | 
 | 505 |         return Location::RegisterLocation(GetRegister()); | 
 | 506 |       } | 
 | 507 |     } | 
| Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 508 |   } else { | 
 | 509 |     HInstruction* defined_by = GetParent()->GetDefinedBy(); | 
 | 510 |     if (defined_by->IsConstant()) { | 
 | 511 |       return defined_by->GetLocations()->Out(); | 
 | 512 |     } else if (GetParent()->HasSpillSlot()) { | 
| Aart Bik | cc89525 | 2017-03-21 10:55:15 -0700 | [diff] [blame] | 513 |       switch (NumberOfSpillSlotsNeeded()) { | 
 | 514 |         case 1: return Location::StackSlot(GetParent()->GetSpillSlot()); | 
 | 515 |         case 2: return Location::DoubleStackSlot(GetParent()->GetSpillSlot()); | 
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 516 |         case 4: return Location::SIMDStackSlot(GetParent()->GetSpillSlot()); | 
| Aart Bik | cc89525 | 2017-03-21 10:55:15 -0700 | [diff] [blame] | 517 |         default: LOG(FATAL) << "Unexpected number of spill slots"; UNREACHABLE(); | 
| Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 518 |       } | 
 | 519 |     } else { | 
 | 520 |       return Location(); | 
 | 521 |     } | 
 | 522 |   } | 
 | 523 | } | 
 | 524 |  | 
| David Brazdil | 5b8e6a5 | 2015-02-25 16:17:05 +0000 | [diff] [blame] | 525 | Location LiveInterval::GetLocationAt(size_t position) { | 
| David Brazdil | 241a486 | 2015-04-16 17:59:03 +0100 | [diff] [blame] | 526 |   LiveInterval* sibling = GetSiblingAt(position); | 
 | 527 |   DCHECK(sibling != nullptr); | 
 | 528 |   return sibling->ToLocation(); | 
| Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 529 | } | 
 | 530 |  | 
| David Brazdil | 241a486 | 2015-04-16 17:59:03 +0100 | [diff] [blame] | 531 | LiveInterval* LiveInterval::GetSiblingAt(size_t position) { | 
| David Brazdil | 5b8e6a5 | 2015-02-25 16:17:05 +0000 | [diff] [blame] | 532 |   LiveInterval* current = this; | 
| David Brazdil | 241a486 | 2015-04-16 17:59:03 +0100 | [diff] [blame] | 533 |   while (current != nullptr && !current->IsDefinedAt(position)) { | 
| Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 534 |     current = current->GetNextSibling(); | 
| Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 535 |   } | 
| David Brazdil | 241a486 | 2015-04-16 17:59:03 +0100 | [diff] [blame] | 536 |   return current; | 
| Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 537 | } | 
 | 538 |  | 
| Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 539 | }  // namespace art |