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 | #ifndef ART_COMPILER_OPTIMIZING_SSA_LIVENESS_ANALYSIS_H_ |
| 18 | #define ART_COMPILER_OPTIMIZING_SSA_LIVENESS_ANALYSIS_H_ |
| 19 | |
| 20 | #include "nodes.h" |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 21 | #include <iostream> |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 22 | |
| 23 | namespace art { |
| 24 | |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 25 | class CodeGenerator; |
Nicolas Geoffray | fbda5f3 | 2015-04-29 14:16:00 +0100 | [diff] [blame] | 26 | class SsaLivenessAnalysis; |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 27 | |
Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 28 | static constexpr int kNoRegister = -1; |
| 29 | |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 30 | class BlockInfo : public ArenaObject<kArenaAllocSsaLiveness> { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 31 | public: |
| 32 | BlockInfo(ArenaAllocator* allocator, const HBasicBlock& block, size_t number_of_ssa_values) |
| 33 | : block_(block), |
| 34 | live_in_(allocator, number_of_ssa_values, false), |
| 35 | live_out_(allocator, number_of_ssa_values, false), |
| 36 | kill_(allocator, number_of_ssa_values, false) { |
Ian Rogers | cf7f191 | 2014-10-22 22:06:39 -0700 | [diff] [blame] | 37 | UNUSED(block_); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 38 | live_in_.ClearAllBits(); |
| 39 | live_out_.ClearAllBits(); |
| 40 | kill_.ClearAllBits(); |
| 41 | } |
| 42 | |
| 43 | private: |
| 44 | const HBasicBlock& block_; |
| 45 | ArenaBitVector live_in_; |
| 46 | ArenaBitVector live_out_; |
| 47 | ArenaBitVector kill_; |
| 48 | |
| 49 | friend class SsaLivenessAnalysis; |
| 50 | |
| 51 | DISALLOW_COPY_AND_ASSIGN(BlockInfo); |
| 52 | }; |
| 53 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 54 | /** |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 55 | * A live range contains the start and end of a range where an instruction or a temporary |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 56 | * is live. |
| 57 | */ |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 58 | class LiveRange FINAL : public ArenaObject<kArenaAllocSsaLiveness> { |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 59 | public: |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 60 | LiveRange(size_t start, size_t end, LiveRange* next) : start_(start), end_(end), next_(next) { |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 61 | DCHECK_LT(start, end); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 62 | DCHECK(next_ == nullptr || next_->GetStart() > GetEnd()); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | size_t GetStart() const { return start_; } |
| 66 | size_t GetEnd() const { return end_; } |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 67 | LiveRange* GetNext() const { return next_; } |
| 68 | |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 69 | bool IntersectsWith(const LiveRange& other) const { |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 70 | return (start_ >= other.start_ && start_ < other.end_) |
| 71 | || (other.start_ >= start_ && other.start_ < end_); |
| 72 | } |
| 73 | |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 74 | bool IsBefore(const LiveRange& other) const { |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 75 | return end_ <= other.start_; |
| 76 | } |
| 77 | |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 78 | void Dump(std::ostream& stream) const { |
David Brazdil | c7a2485 | 2015-05-15 16:44:05 +0100 | [diff] [blame] | 79 | stream << "[" << start_ << "," << end_ << ")"; |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 80 | } |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 81 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 82 | LiveRange* Dup(ArenaAllocator* allocator) const { |
| 83 | return new (allocator) LiveRange( |
| 84 | start_, end_, next_ == nullptr ? nullptr : next_->Dup(allocator)); |
| 85 | } |
| 86 | |
| 87 | LiveRange* GetLastRange() { |
| 88 | return next_ == nullptr ? this : next_->GetLastRange(); |
| 89 | } |
| 90 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 91 | private: |
| 92 | size_t start_; |
Nicolas Geoffray | 7690562 | 2014-09-25 14:39:26 +0100 | [diff] [blame] | 93 | size_t end_; |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 94 | LiveRange* next_; |
| 95 | |
| 96 | friend class LiveInterval; |
| 97 | |
| 98 | DISALLOW_COPY_AND_ASSIGN(LiveRange); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 99 | }; |
| 100 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 101 | /** |
| 102 | * A use position represents a live interval use at a given position. |
| 103 | */ |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 104 | class UsePosition : public ArenaObject<kArenaAllocSsaLiveness> { |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 105 | public: |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 106 | UsePosition(HInstruction* user, |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 107 | HEnvironment* environment, |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 108 | size_t input_index, |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 109 | size_t position, |
| 110 | UsePosition* next) |
| 111 | : user_(user), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 112 | environment_(environment), |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 113 | input_index_(input_index), |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 114 | position_(position), |
| 115 | next_(next) { |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 116 | DCHECK((user == nullptr) |
| 117 | || user->IsPhi() |
Nicolas Geoffray | 7690562 | 2014-09-25 14:39:26 +0100 | [diff] [blame] | 118 | || (GetPosition() == user->GetLifetimePosition() + 1) |
| 119 | || (GetPosition() == user->GetLifetimePosition())); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 120 | DCHECK(environment == nullptr || user == nullptr); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 121 | DCHECK(next_ == nullptr || next->GetPosition() >= GetPosition()); |
| 122 | } |
| 123 | |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 124 | static constexpr size_t kNoInput = -1; |
| 125 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 126 | size_t GetPosition() const { return position_; } |
| 127 | |
| 128 | UsePosition* GetNext() const { return next_; } |
Nicolas Geoffray | 7690562 | 2014-09-25 14:39:26 +0100 | [diff] [blame] | 129 | void SetNext(UsePosition* next) { next_ = next; } |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 130 | |
| 131 | HInstruction* GetUser() const { return user_; } |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 132 | HEnvironment* GetEnvironment() const { return environment_; } |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 133 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 134 | bool GetIsEnvironment() const { return environment_ != nullptr; } |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 135 | bool IsSynthesized() const { return user_ == nullptr; } |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 136 | |
| 137 | size_t GetInputIndex() const { return input_index_; } |
| 138 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 139 | void Dump(std::ostream& stream) const { |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 140 | stream << position_; |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | HLoopInformation* GetLoopInformation() const { |
| 144 | return user_->GetBlock()->GetLoopInformation(); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 145 | } |
| 146 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 147 | UsePosition* Dup(ArenaAllocator* allocator) const { |
| 148 | return new (allocator) UsePosition( |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 149 | user_, environment_, input_index_, position_, |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 150 | next_ == nullptr ? nullptr : next_->Dup(allocator)); |
| 151 | } |
| 152 | |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 153 | bool RequiresRegister() const { |
| 154 | if (GetIsEnvironment()) return false; |
| 155 | if (IsSynthesized()) return false; |
| 156 | Location location = GetUser()->GetLocations()->InAt(GetInputIndex()); |
| 157 | return location.IsUnallocated() |
| 158 | && (location.GetPolicy() == Location::kRequiresRegister |
| 159 | || location.GetPolicy() == Location::kRequiresFpuRegister); |
| 160 | } |
| 161 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 162 | private: |
| 163 | HInstruction* const user_; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 164 | HEnvironment* const environment_; |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 165 | const size_t input_index_; |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 166 | const size_t position_; |
Nicolas Geoffray | 7690562 | 2014-09-25 14:39:26 +0100 | [diff] [blame] | 167 | UsePosition* next_; |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 168 | |
| 169 | DISALLOW_COPY_AND_ASSIGN(UsePosition); |
| 170 | }; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 171 | |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 172 | class SafepointPosition : public ArenaObject<kArenaAllocSsaLiveness> { |
Nicolas Geoffray | 5588e58 | 2015-04-14 14:10:59 +0100 | [diff] [blame] | 173 | public: |
| 174 | explicit SafepointPosition(HInstruction* instruction) |
| 175 | : instruction_(instruction), |
| 176 | next_(nullptr) {} |
| 177 | |
| 178 | void SetNext(SafepointPosition* next) { |
| 179 | next_ = next; |
| 180 | } |
| 181 | |
| 182 | size_t GetPosition() const { |
| 183 | return instruction_->GetLifetimePosition(); |
| 184 | } |
| 185 | |
| 186 | SafepointPosition* GetNext() const { |
| 187 | return next_; |
| 188 | } |
| 189 | |
| 190 | LocationSummary* GetLocations() const { |
| 191 | return instruction_->GetLocations(); |
| 192 | } |
| 193 | |
| 194 | HInstruction* GetInstruction() const { |
| 195 | return instruction_; |
| 196 | } |
| 197 | |
| 198 | private: |
| 199 | HInstruction* const instruction_; |
| 200 | SafepointPosition* next_; |
| 201 | |
| 202 | DISALLOW_COPY_AND_ASSIGN(SafepointPosition); |
| 203 | }; |
| 204 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 205 | /** |
| 206 | * An interval is a list of disjoint live ranges where an instruction is live. |
| 207 | * Each instruction that has uses gets an interval. |
| 208 | */ |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 209 | class LiveInterval : public ArenaObject<kArenaAllocSsaLiveness> { |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 210 | public: |
Mingyao Yang | 296bd60 | 2014-10-06 16:47:28 -0700 | [diff] [blame] | 211 | static LiveInterval* MakeInterval(ArenaAllocator* allocator, |
| 212 | Primitive::Type type, |
| 213 | HInstruction* instruction = nullptr) { |
| 214 | return new (allocator) LiveInterval(allocator, type, instruction); |
| 215 | } |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 216 | |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 217 | static LiveInterval* MakeSlowPathInterval(ArenaAllocator* allocator, HInstruction* instruction) { |
| 218 | return new (allocator) LiveInterval( |
| 219 | allocator, Primitive::kPrimVoid, instruction, false, kNoRegister, false, true); |
| 220 | } |
| 221 | |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 222 | static LiveInterval* MakeFixedInterval(ArenaAllocator* allocator, int reg, Primitive::Type type) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 223 | return new (allocator) LiveInterval(allocator, type, nullptr, true, reg, false); |
| 224 | } |
| 225 | |
Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 226 | static LiveInterval* MakeTempInterval(ArenaAllocator* allocator, Primitive::Type type) { |
| 227 | return new (allocator) LiveInterval(allocator, type, nullptr, false, kNoRegister, true); |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | bool IsFixed() const { return is_fixed_; } |
Mingyao Yang | 296bd60 | 2014-10-06 16:47:28 -0700 | [diff] [blame] | 231 | bool IsTemp() const { return is_temp_; } |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 232 | bool IsSlowPathSafepoint() const { return is_slow_path_safepoint_; } |
Mingyao Yang | 296bd60 | 2014-10-06 16:47:28 -0700 | [diff] [blame] | 233 | // This interval is the result of a split. |
| 234 | bool IsSplit() const { return parent_ != this; } |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 235 | |
Nicolas Geoffray | f01d344 | 2015-03-27 17:15:49 +0000 | [diff] [blame] | 236 | void AddTempUse(HInstruction* instruction, size_t temp_index) { |
| 237 | DCHECK(IsTemp()); |
| 238 | DCHECK(first_use_ == nullptr) << "A temporary can only have one user"; |
Nicolas Geoffray | 4ed947a | 2015-04-27 16:58:06 +0100 | [diff] [blame] | 239 | DCHECK(first_env_use_ == nullptr) << "A temporary cannot have environment user"; |
Nicolas Geoffray | f01d344 | 2015-03-27 17:15:49 +0000 | [diff] [blame] | 240 | size_t position = instruction->GetLifetimePosition(); |
| 241 | first_use_ = new (allocator_) UsePosition( |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 242 | instruction, /* environment */ nullptr, temp_index, position, first_use_); |
Nicolas Geoffray | f01d344 | 2015-03-27 17:15:49 +0000 | [diff] [blame] | 243 | AddRange(position, position + 1); |
| 244 | } |
| 245 | |
Nicolas Geoffray | d8126be | 2015-03-27 10:22:41 +0000 | [diff] [blame] | 246 | void AddUse(HInstruction* instruction, |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 247 | HEnvironment* environment, |
Nicolas Geoffray | d8126be | 2015-03-27 10:22:41 +0000 | [diff] [blame] | 248 | size_t input_index, |
Nicolas Geoffray | d8126be | 2015-03-27 10:22:41 +0000 | [diff] [blame] | 249 | bool keep_alive = false) { |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 250 | // Set the use within the instruction. |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 251 | bool is_environment = (environment != nullptr); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 252 | size_t position = instruction->GetLifetimePosition() + 1; |
| 253 | LocationSummary* locations = instruction->GetLocations(); |
| 254 | if (!is_environment) { |
| 255 | if (locations->IsFixedInput(input_index) || locations->OutputUsesSameAs(input_index)) { |
| 256 | // For fixed inputs and output same as input, the register allocator |
| 257 | // requires to have inputs die at the instruction, so that input moves use the |
| 258 | // location of the input just before that instruction (and not potential moves due |
| 259 | // to splitting). |
| 260 | position = instruction->GetLifetimePosition(); |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 261 | } else if (!locations->InAt(input_index).IsValid()) { |
| 262 | return; |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 263 | } |
Nicolas Geoffray | 7690562 | 2014-09-25 14:39:26 +0100 | [diff] [blame] | 264 | } |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 265 | |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 266 | if (!is_environment && instruction->IsInLoop()) { |
| 267 | AddBackEdgeUses(*instruction->GetBlock()); |
| 268 | } |
| 269 | |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 270 | DCHECK(position == instruction->GetLifetimePosition() |
| 271 | || position == instruction->GetLifetimePosition() + 1); |
| 272 | |
Nicolas Geoffray | 7690562 | 2014-09-25 14:39:26 +0100 | [diff] [blame] | 273 | if ((first_use_ != nullptr) |
| 274 | && (first_use_->GetUser() == instruction) |
| 275 | && (first_use_->GetPosition() < position)) { |
| 276 | // The user uses the instruction multiple times, and one use dies before the other. |
| 277 | // We update the use list so that the latter is first. |
Nicolas Geoffray | d8126be | 2015-03-27 10:22:41 +0000 | [diff] [blame] | 278 | DCHECK(!is_environment); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 279 | UsePosition* cursor = first_use_; |
| 280 | while ((cursor->GetNext() != nullptr) && (cursor->GetNext()->GetPosition() < position)) { |
| 281 | cursor = cursor->GetNext(); |
| 282 | } |
Nicolas Geoffray | 7690562 | 2014-09-25 14:39:26 +0100 | [diff] [blame] | 283 | DCHECK(first_use_->GetPosition() + 1 == position); |
| 284 | UsePosition* new_use = new (allocator_) UsePosition( |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 285 | instruction, nullptr /* environment */, input_index, position, cursor->GetNext()); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 286 | cursor->SetNext(new_use); |
Nicolas Geoffray | 7690562 | 2014-09-25 14:39:26 +0100 | [diff] [blame] | 287 | if (first_range_->GetEnd() == first_use_->GetPosition()) { |
| 288 | first_range_->end_ = position; |
| 289 | } |
| 290 | return; |
| 291 | } |
| 292 | |
Nicolas Geoffray | 4ed947a | 2015-04-27 16:58:06 +0100 | [diff] [blame] | 293 | if (is_environment) { |
| 294 | first_env_use_ = new (allocator_) UsePosition( |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 295 | nullptr /* instruction */, environment, input_index, position, first_env_use_); |
Nicolas Geoffray | 4ed947a | 2015-04-27 16:58:06 +0100 | [diff] [blame] | 296 | } else { |
| 297 | first_use_ = new (allocator_) UsePosition( |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 298 | instruction, nullptr /* environment */, input_index, position, first_use_); |
Nicolas Geoffray | 4ed947a | 2015-04-27 16:58:06 +0100 | [diff] [blame] | 299 | } |
Nicolas Geoffray | d8126be | 2015-03-27 10:22:41 +0000 | [diff] [blame] | 300 | |
| 301 | if (is_environment && !keep_alive) { |
| 302 | // If this environment use does not keep the instruction live, it does not |
| 303 | // affect the live range of that instruction. |
| 304 | return; |
| 305 | } |
| 306 | |
Nicolas Geoffray | 8ddb00c | 2014-09-29 12:00:40 +0100 | [diff] [blame] | 307 | size_t start_block_position = instruction->GetBlock()->GetLifetimeStart(); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 308 | if (first_range_ == nullptr) { |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 309 | // First time we see a use of that interval. |
David Brazdil | 3fc992f | 2015-04-16 18:31:55 +0100 | [diff] [blame] | 310 | first_range_ = last_range_ = range_search_start_ = |
| 311 | new (allocator_) LiveRange(start_block_position, position, nullptr); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 312 | } else if (first_range_->GetStart() == start_block_position) { |
Nicolas Geoffray | 8ddb00c | 2014-09-29 12:00:40 +0100 | [diff] [blame] | 313 | // There is a use later in the same block or in a following block. |
| 314 | // Note that in such a case, `AddRange` for the whole blocks has been called |
| 315 | // before arriving in this method, and this is the reason the start of |
| 316 | // `first_range_` is before the given `position`. |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 317 | DCHECK_LE(position, first_range_->GetEnd()); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 318 | } else { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 319 | DCHECK(first_range_->GetStart() > position); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 320 | // There is a hole in the interval. Create a new range. |
Nicolas Geoffray | 8ddb00c | 2014-09-29 12:00:40 +0100 | [diff] [blame] | 321 | // Note that the start of `first_range_` can be equal to `end`: two blocks |
| 322 | // having adjacent lifetime positions are not necessarily |
| 323 | // predecessor/successor. When two blocks are predecessor/successor, the |
| 324 | // liveness algorithm has called `AddRange` before arriving in this method, |
| 325 | // and the check line 205 would succeed. |
David Brazdil | 3fc992f | 2015-04-16 18:31:55 +0100 | [diff] [blame] | 326 | first_range_ = range_search_start_ = |
| 327 | new (allocator_) LiveRange(start_block_position, position, first_range_); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 328 | } |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 329 | } |
| 330 | |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 331 | void AddPhiUse(HInstruction* instruction, size_t input_index, HBasicBlock* block) { |
Nicolas Geoffray | 7690562 | 2014-09-25 14:39:26 +0100 | [diff] [blame] | 332 | DCHECK(instruction->IsPhi()); |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 333 | if (block->IsInLoop()) { |
| 334 | AddBackEdgeUses(*block); |
| 335 | } |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 336 | first_use_ = new (allocator_) UsePosition( |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 337 | instruction, /* environment */ nullptr, input_index, block->GetLifetimeEnd(), first_use_); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | void AddRange(size_t start, size_t end) { |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 341 | if (first_range_ == nullptr) { |
David Brazdil | 3fc992f | 2015-04-16 18:31:55 +0100 | [diff] [blame] | 342 | first_range_ = last_range_ = range_search_start_ = |
| 343 | new (allocator_) LiveRange(start, end, first_range_); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 344 | } else if (first_range_->GetStart() == end) { |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 345 | // There is a use in the following block. |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 346 | first_range_->start_ = start; |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 347 | } else if (first_range_->GetStart() == start && first_range_->GetEnd() == end) { |
| 348 | DCHECK(is_fixed_); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 349 | } else { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 350 | DCHECK_GT(first_range_->GetStart(), end); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 351 | // There is a hole in the interval. Create a new range. |
David Brazdil | 3fc992f | 2015-04-16 18:31:55 +0100 | [diff] [blame] | 352 | first_range_ = range_search_start_ = new (allocator_) LiveRange(start, end, first_range_); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 353 | } |
| 354 | } |
| 355 | |
| 356 | void AddLoopRange(size_t start, size_t end) { |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 357 | DCHECK(first_range_ != nullptr); |
Nicolas Geoffray | aedc328 | 2015-01-23 18:01:51 +0000 | [diff] [blame] | 358 | DCHECK_LE(start, first_range_->GetStart()); |
| 359 | // Find the range that covers the positions after the loop. |
| 360 | LiveRange* after_loop = first_range_; |
| 361 | LiveRange* last_in_loop = nullptr; |
| 362 | while (after_loop != nullptr && after_loop->GetEnd() < end) { |
| 363 | DCHECK_LE(start, after_loop->GetStart()); |
| 364 | last_in_loop = after_loop; |
| 365 | after_loop = after_loop->GetNext(); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 366 | } |
Nicolas Geoffray | aedc328 | 2015-01-23 18:01:51 +0000 | [diff] [blame] | 367 | if (after_loop == nullptr) { |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 368 | // Uses are only in the loop. |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 369 | first_range_ = last_range_ = range_search_start_ = |
| 370 | new (allocator_) LiveRange(start, end, nullptr); |
Nicolas Geoffray | aedc328 | 2015-01-23 18:01:51 +0000 | [diff] [blame] | 371 | } else if (after_loop->GetStart() <= end) { |
David Brazdil | 3fc992f | 2015-04-16 18:31:55 +0100 | [diff] [blame] | 372 | first_range_ = range_search_start_ = after_loop; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 373 | // There are uses after the loop. |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 374 | first_range_->start_ = start; |
Nicolas Geoffray | aedc328 | 2015-01-23 18:01:51 +0000 | [diff] [blame] | 375 | } else { |
| 376 | // The use after the loop is after a lifetime hole. |
| 377 | DCHECK(last_in_loop != nullptr); |
David Brazdil | 3fc992f | 2015-04-16 18:31:55 +0100 | [diff] [blame] | 378 | first_range_ = range_search_start_ = last_in_loop; |
Nicolas Geoffray | aedc328 | 2015-01-23 18:01:51 +0000 | [diff] [blame] | 379 | first_range_->start_ = start; |
| 380 | first_range_->end_ = end; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 381 | } |
| 382 | } |
| 383 | |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 384 | bool HasSpillSlot() const { return spill_slot_ != kNoSpillSlot; } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 385 | void SetSpillSlot(int slot) { |
| 386 | DCHECK(!is_fixed_); |
| 387 | DCHECK(!is_temp_); |
| 388 | spill_slot_ = slot; |
| 389 | } |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 390 | int GetSpillSlot() const { return spill_slot_; } |
| 391 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 392 | void SetFrom(size_t from) { |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 393 | if (first_range_ != nullptr) { |
| 394 | first_range_->start_ = from; |
| 395 | } else { |
| 396 | // Instruction without uses. |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 397 | DCHECK(first_use_ == nullptr); |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 398 | DCHECK(from == defined_by_->GetLifetimePosition()); |
David Brazdil | 3fc992f | 2015-04-16 18:31:55 +0100 | [diff] [blame] | 399 | first_range_ = last_range_ = range_search_start_ = |
| 400 | new (allocator_) LiveRange(from, from + 2, nullptr); |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 401 | } |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 402 | } |
| 403 | |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 404 | LiveInterval* GetParent() const { return parent_; } |
| 405 | |
Nicolas Geoffray | 1ba1981 | 2015-04-21 09:12:40 +0100 | [diff] [blame] | 406 | // Returns whether this interval is the parent interval, that is, the interval |
| 407 | // that starts where the HInstruction is defined. |
| 408 | bool IsParent() const { return parent_ == this; } |
| 409 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 410 | LiveRange* GetFirstRange() const { return first_range_; } |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 411 | LiveRange* GetLastRange() const { return last_range_; } |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 412 | |
| 413 | int GetRegister() const { return register_; } |
| 414 | void SetRegister(int reg) { register_ = reg; } |
| 415 | void ClearRegister() { register_ = kNoRegister; } |
| 416 | bool HasRegister() const { return register_ != kNoRegister; } |
| 417 | |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 418 | bool IsDeadAt(size_t position) const { |
David Brazdil | 241a486 | 2015-04-16 17:59:03 +0100 | [diff] [blame] | 419 | return GetEnd() <= position; |
| 420 | } |
| 421 | |
| 422 | bool IsDefinedAt(size_t position) const { |
| 423 | return GetStart() <= position && !IsDeadAt(position); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 424 | } |
| 425 | |
David Brazdil | 3fc992f | 2015-04-16 18:31:55 +0100 | [diff] [blame] | 426 | // Returns true if the interval contains a LiveRange covering `position`. |
| 427 | // The range at or immediately after the current position of linear scan |
| 428 | // is cached for better performance. If `position` can be smaller than |
| 429 | // that, CoversSlow should be used instead. |
David Brazdil | 5b8e6a5 | 2015-02-25 16:17:05 +0000 | [diff] [blame] | 430 | bool Covers(size_t position) { |
David Brazdil | 3fc992f | 2015-04-16 18:31:55 +0100 | [diff] [blame] | 431 | LiveRange* candidate = FindRangeAtOrAfter(position, range_search_start_); |
| 432 | range_search_start_ = candidate; |
| 433 | return (candidate != nullptr && candidate->GetStart() <= position); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 434 | } |
| 435 | |
David Brazdil | 3fc992f | 2015-04-16 18:31:55 +0100 | [diff] [blame] | 436 | // Same as Covers but always tests all ranges. |
| 437 | bool CoversSlow(size_t position) const { |
| 438 | LiveRange* candidate = FindRangeAtOrAfter(position, first_range_); |
| 439 | return candidate != nullptr && candidate->GetStart() <= position; |
| 440 | } |
| 441 | |
| 442 | // Returns the first intersection of this interval with `current`, which |
| 443 | // must be the interval currently being allocated by linear scan. |
| 444 | size_t FirstIntersectionWith(LiveInterval* current) const { |
| 445 | // Find the first range after the start of `current`. We use the search |
| 446 | // cache to improve performance. |
| 447 | DCHECK(GetStart() <= current->GetStart() || IsFixed()); |
| 448 | LiveRange* other_range = current->first_range_; |
| 449 | LiveRange* my_range = FindRangeAtOrAfter(other_range->GetStart(), range_search_start_); |
| 450 | if (my_range == nullptr) { |
| 451 | return kNoLifetime; |
| 452 | } |
| 453 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 454 | // Advance both intervals and find the first matching range start in |
| 455 | // this interval. |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 456 | do { |
David Brazdil | 714e14f | 2015-02-25 11:57:05 +0000 | [diff] [blame] | 457 | if (my_range->IsBefore(*other_range)) { |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 458 | my_range = my_range->GetNext(); |
| 459 | if (my_range == nullptr) { |
| 460 | return kNoLifetime; |
| 461 | } |
David Brazdil | 714e14f | 2015-02-25 11:57:05 +0000 | [diff] [blame] | 462 | } else if (other_range->IsBefore(*my_range)) { |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 463 | other_range = other_range->GetNext(); |
| 464 | if (other_range == nullptr) { |
| 465 | return kNoLifetime; |
| 466 | } |
David Brazdil | 714e14f | 2015-02-25 11:57:05 +0000 | [diff] [blame] | 467 | } else { |
| 468 | DCHECK(my_range->IntersectsWith(*other_range)); |
| 469 | return std::max(my_range->GetStart(), other_range->GetStart()); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 470 | } |
| 471 | } while (true); |
| 472 | } |
| 473 | |
| 474 | size_t GetStart() const { |
| 475 | return first_range_->GetStart(); |
| 476 | } |
| 477 | |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 478 | size_t GetEnd() const { |
| 479 | return last_range_->GetEnd(); |
| 480 | } |
| 481 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 482 | size_t FirstRegisterUseAfter(size_t position) const { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 483 | if (is_temp_) { |
| 484 | return position == GetStart() ? position : kNoLifetime; |
| 485 | } |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 486 | |
| 487 | if (IsDefiningPosition(position) && DefinitionRequiresRegister()) { |
| 488 | return position; |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 489 | } |
| 490 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 491 | UsePosition* use = first_use_; |
Nicolas Geoffray | de025a7 | 2014-06-19 17:06:46 +0100 | [diff] [blame] | 492 | size_t end = GetEnd(); |
| 493 | while (use != nullptr && use->GetPosition() <= end) { |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 494 | size_t use_position = use->GetPosition(); |
Nicolas Geoffray | 4ed947a | 2015-04-27 16:58:06 +0100 | [diff] [blame] | 495 | if (use_position > position) { |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 496 | if (use->RequiresRegister()) { |
Nicolas Geoffray | c8147a7 | 2014-10-21 16:06:20 +0100 | [diff] [blame] | 497 | return use_position; |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 498 | } |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 499 | } |
| 500 | use = use->GetNext(); |
| 501 | } |
| 502 | return kNoLifetime; |
| 503 | } |
| 504 | |
| 505 | size_t FirstRegisterUse() const { |
| 506 | return FirstRegisterUseAfter(GetStart()); |
| 507 | } |
| 508 | |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 509 | size_t FirstUseAfter(size_t position) const { |
| 510 | if (is_temp_) { |
| 511 | return position == GetStart() ? position : kNoLifetime; |
| 512 | } |
| 513 | |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 514 | if (IsDefiningPosition(position)) { |
| 515 | DCHECK(defined_by_->GetLocations()->Out().IsValid()); |
| 516 | return position; |
Nicolas Geoffray | 1ba1981 | 2015-04-21 09:12:40 +0100 | [diff] [blame] | 517 | } |
| 518 | |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 519 | UsePosition* use = first_use_; |
| 520 | size_t end = GetEnd(); |
| 521 | while (use != nullptr && use->GetPosition() <= end) { |
Nicolas Geoffray | 4ed947a | 2015-04-27 16:58:06 +0100 | [diff] [blame] | 522 | size_t use_position = use->GetPosition(); |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 523 | if (use_position > position) { |
Nicolas Geoffray | 4ed947a | 2015-04-27 16:58:06 +0100 | [diff] [blame] | 524 | return use_position; |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 525 | } |
| 526 | use = use->GetNext(); |
| 527 | } |
| 528 | return kNoLifetime; |
| 529 | } |
| 530 | |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 531 | UsePosition* GetFirstUse() const { |
| 532 | return first_use_; |
| 533 | } |
| 534 | |
Nicolas Geoffray | 4ed947a | 2015-04-27 16:58:06 +0100 | [diff] [blame] | 535 | UsePosition* GetFirstEnvironmentUse() const { |
| 536 | return first_env_use_; |
| 537 | } |
| 538 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 539 | Primitive::Type GetType() const { |
| 540 | return type_; |
| 541 | } |
| 542 | |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 543 | HInstruction* GetDefinedBy() const { |
| 544 | return defined_by_; |
| 545 | } |
| 546 | |
Nicolas Geoffray | 8826f67 | 2015-04-17 09:15:11 +0100 | [diff] [blame] | 547 | bool HasWillCallSafepoint() const { |
| 548 | for (SafepointPosition* safepoint = first_safepoint_; |
| 549 | safepoint != nullptr; |
| 550 | safepoint = safepoint->GetNext()) { |
| 551 | if (safepoint->GetLocations()->WillCall()) return true; |
| 552 | } |
| 553 | return false; |
| 554 | } |
| 555 | |
Nicolas Geoffray | 43af728 | 2015-04-16 13:01:01 +0100 | [diff] [blame] | 556 | SafepointPosition* FindSafepointJustBefore(size_t position) const { |
| 557 | for (SafepointPosition* safepoint = first_safepoint_, *previous = nullptr; |
| 558 | safepoint != nullptr; |
| 559 | previous = safepoint, safepoint = safepoint->GetNext()) { |
| 560 | if (safepoint->GetPosition() >= position) return previous; |
| 561 | } |
| 562 | return last_safepoint_; |
| 563 | } |
| 564 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 565 | /** |
| 566 | * Split this interval at `position`. This interval is changed to: |
| 567 | * [start ... position). |
| 568 | * |
| 569 | * The new interval covers: |
| 570 | * [position ... end) |
| 571 | */ |
| 572 | LiveInterval* SplitAt(size_t position) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 573 | DCHECK(!is_temp_); |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 574 | DCHECK(!is_fixed_); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 575 | DCHECK_GT(position, GetStart()); |
| 576 | |
David Brazdil | 241a486 | 2015-04-16 17:59:03 +0100 | [diff] [blame] | 577 | if (GetEnd() <= position) { |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 578 | // This range dies before `position`, no need to split. |
| 579 | return nullptr; |
| 580 | } |
| 581 | |
| 582 | LiveInterval* new_interval = new (allocator_) LiveInterval(allocator_, type_); |
Nicolas Geoffray | 43af728 | 2015-04-16 13:01:01 +0100 | [diff] [blame] | 583 | SafepointPosition* new_last_safepoint = FindSafepointJustBefore(position); |
| 584 | if (new_last_safepoint == nullptr) { |
| 585 | new_interval->first_safepoint_ = first_safepoint_; |
| 586 | new_interval->last_safepoint_ = last_safepoint_; |
| 587 | first_safepoint_ = last_safepoint_ = nullptr; |
| 588 | } else if (last_safepoint_ != new_last_safepoint) { |
| 589 | new_interval->last_safepoint_ = last_safepoint_; |
| 590 | new_interval->first_safepoint_ = new_last_safepoint->GetNext(); |
| 591 | DCHECK(new_interval->first_safepoint_ != nullptr); |
| 592 | last_safepoint_ = new_last_safepoint; |
| 593 | last_safepoint_->SetNext(nullptr); |
| 594 | } |
| 595 | |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 596 | new_interval->next_sibling_ = next_sibling_; |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 597 | next_sibling_ = new_interval; |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 598 | new_interval->parent_ = parent_; |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 599 | |
| 600 | new_interval->first_use_ = first_use_; |
Nicolas Geoffray | 4ed947a | 2015-04-27 16:58:06 +0100 | [diff] [blame] | 601 | new_interval->first_env_use_ = first_env_use_; |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 602 | LiveRange* current = first_range_; |
| 603 | LiveRange* previous = nullptr; |
| 604 | // Iterate over the ranges, and either find a range that covers this position, or |
Nicolas Geoffray | dd8f887 | 2015-01-15 15:37:37 +0000 | [diff] [blame] | 605 | // two ranges in between this position (that is, the position is in a lifetime hole). |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 606 | do { |
| 607 | if (position >= current->GetEnd()) { |
| 608 | // Move to next range. |
| 609 | previous = current; |
| 610 | current = current->next_; |
| 611 | } else if (position <= current->GetStart()) { |
| 612 | // If the previous range did not cover this position, we know position is in |
| 613 | // a lifetime hole. We can just break the first_range_ and last_range_ links |
| 614 | // and return the new interval. |
| 615 | DCHECK(previous != nullptr); |
| 616 | DCHECK(current != first_range_); |
| 617 | new_interval->last_range_ = last_range_; |
| 618 | last_range_ = previous; |
| 619 | previous->next_ = nullptr; |
| 620 | new_interval->first_range_ = current; |
David Brazdil | 3fc992f | 2015-04-16 18:31:55 +0100 | [diff] [blame] | 621 | if (range_search_start_ != nullptr && range_search_start_->GetEnd() >= current->GetEnd()) { |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 622 | // Search start point is inside `new_interval`. Change it to null |
David Brazdil | 3fc992f | 2015-04-16 18:31:55 +0100 | [diff] [blame] | 623 | // (i.e. the end of the interval) in the original interval. |
| 624 | range_search_start_ = nullptr; |
| 625 | } |
| 626 | new_interval->range_search_start_ = new_interval->first_range_; |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 627 | return new_interval; |
| 628 | } else { |
| 629 | // This range covers position. We create a new last_range_ for this interval |
| 630 | // that covers last_range_->Start() and position. We also shorten the current |
| 631 | // range and make it the first range of the new interval. |
| 632 | DCHECK(position < current->GetEnd() && position > current->GetStart()); |
| 633 | new_interval->last_range_ = last_range_; |
| 634 | last_range_ = new (allocator_) LiveRange(current->start_, position, nullptr); |
| 635 | if (previous != nullptr) { |
| 636 | previous->next_ = last_range_; |
| 637 | } else { |
| 638 | first_range_ = last_range_; |
| 639 | } |
| 640 | new_interval->first_range_ = current; |
| 641 | current->start_ = position; |
David Brazdil | 3fc992f | 2015-04-16 18:31:55 +0100 | [diff] [blame] | 642 | if (range_search_start_ != nullptr && range_search_start_->GetEnd() >= current->GetEnd()) { |
| 643 | // Search start point is inside `new_interval`. Change it to `last_range` |
| 644 | // in the original interval. This is conservative but always correct. |
| 645 | range_search_start_ = last_range_; |
| 646 | } |
| 647 | new_interval->range_search_start_ = new_interval->first_range_; |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 648 | return new_interval; |
| 649 | } |
| 650 | } while (current != nullptr); |
| 651 | |
| 652 | LOG(FATAL) << "Unreachable"; |
| 653 | return nullptr; |
| 654 | } |
| 655 | |
Nicolas Geoffray | 7690562 | 2014-09-25 14:39:26 +0100 | [diff] [blame] | 656 | bool StartsBeforeOrAt(LiveInterval* other) const { |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 657 | return GetStart() <= other->GetStart(); |
| 658 | } |
| 659 | |
| 660 | bool StartsAfter(LiveInterval* other) const { |
Nicolas Geoffray | 7690562 | 2014-09-25 14:39:26 +0100 | [diff] [blame] | 661 | return GetStart() > other->GetStart(); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 662 | } |
| 663 | |
| 664 | void Dump(std::ostream& stream) const { |
| 665 | stream << "ranges: { "; |
| 666 | LiveRange* current = first_range_; |
Nicolas Geoffray | aedc328 | 2015-01-23 18:01:51 +0000 | [diff] [blame] | 667 | while (current != nullptr) { |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 668 | current->Dump(stream); |
| 669 | stream << " "; |
Nicolas Geoffray | aedc328 | 2015-01-23 18:01:51 +0000 | [diff] [blame] | 670 | current = current->GetNext(); |
| 671 | } |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 672 | stream << "}, uses: { "; |
| 673 | UsePosition* use = first_use_; |
| 674 | if (use != nullptr) { |
| 675 | do { |
| 676 | use->Dump(stream); |
| 677 | stream << " "; |
| 678 | } while ((use = use->GetNext()) != nullptr); |
| 679 | } |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 680 | stream << "}, { "; |
Nicolas Geoffray | 4ed947a | 2015-04-27 16:58:06 +0100 | [diff] [blame] | 681 | use = first_env_use_; |
| 682 | if (use != nullptr) { |
| 683 | do { |
| 684 | use->Dump(stream); |
| 685 | stream << " "; |
| 686 | } while ((use = use->GetNext()) != nullptr); |
| 687 | } |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 688 | stream << "}"; |
Mingyao Yang | 296bd60 | 2014-10-06 16:47:28 -0700 | [diff] [blame] | 689 | stream << " is_fixed: " << is_fixed_ << ", is_split: " << IsSplit(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 690 | stream << " is_low: " << IsLowInterval(); |
Nicolas Geoffray | 4ed947a | 2015-04-27 16:58:06 +0100 | [diff] [blame] | 691 | stream << " is_high: " << IsHighInterval(); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | LiveInterval* GetNextSibling() const { return next_sibling_; } |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 695 | LiveInterval* GetLastSibling() { |
| 696 | LiveInterval* result = this; |
| 697 | while (result->next_sibling_ != nullptr) { |
| 698 | result = result->next_sibling_; |
| 699 | } |
| 700 | return result; |
| 701 | } |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 702 | |
Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 703 | // Returns the first register hint that is at least free before |
| 704 | // the value contained in `free_until`. If none is found, returns |
| 705 | // `kNoRegister`. |
Nicolas Geoffray | fbda5f3 | 2015-04-29 14:16:00 +0100 | [diff] [blame] | 706 | int FindFirstRegisterHint(size_t* free_until, const SsaLivenessAnalysis& liveness) const; |
Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 707 | |
| 708 | // If there is enough at the definition site to find a register (for example |
| 709 | // it uses the same input as the first input), returns the register as a hint. |
| 710 | // Returns kNoRegister otherwise. |
| 711 | int FindHintAtDefinition() const; |
| 712 | |
| 713 | // Returns whether the interval needs two (Dex virtual register size `kVRegSize`) |
| 714 | // slots for spilling. |
| 715 | bool NeedsTwoSpillSlots() const; |
| 716 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 717 | bool IsFloatingPoint() const { |
| 718 | return type_ == Primitive::kPrimFloat || type_ == Primitive::kPrimDouble; |
| 719 | } |
| 720 | |
Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 721 | // Converts the location of the interval to a `Location` object. |
| 722 | Location ToLocation() const; |
| 723 | |
| 724 | // Returns the location of the interval following its siblings at `position`. |
David Brazdil | 5b8e6a5 | 2015-02-25 16:17:05 +0000 | [diff] [blame] | 725 | Location GetLocationAt(size_t position); |
Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 726 | |
David Brazdil | 241a486 | 2015-04-16 17:59:03 +0100 | [diff] [blame] | 727 | // Finds the sibling that is defined at `position`. |
| 728 | LiveInterval* GetSiblingAt(size_t position); |
Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 729 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 730 | // Returns whether `other` and `this` share the same kind of register. |
| 731 | bool SameRegisterKind(Location other) const; |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 732 | bool SameRegisterKind(const LiveInterval& other) const { |
| 733 | return IsFloatingPoint() == other.IsFloatingPoint(); |
| 734 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 735 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 736 | bool HasHighInterval() const { |
Nicolas Geoffray | 3747b48 | 2015-01-19 17:17:16 +0000 | [diff] [blame] | 737 | return IsLowInterval(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 738 | } |
| 739 | |
| 740 | bool HasLowInterval() const { |
| 741 | return IsHighInterval(); |
| 742 | } |
| 743 | |
| 744 | LiveInterval* GetLowInterval() const { |
| 745 | DCHECK(HasLowInterval()); |
| 746 | return high_or_low_interval_; |
| 747 | } |
| 748 | |
| 749 | LiveInterval* GetHighInterval() const { |
| 750 | DCHECK(HasHighInterval()); |
| 751 | return high_or_low_interval_; |
| 752 | } |
| 753 | |
| 754 | bool IsHighInterval() const { |
| 755 | return GetParent()->is_high_interval_; |
| 756 | } |
| 757 | |
| 758 | bool IsLowInterval() const { |
| 759 | return !IsHighInterval() && (GetParent()->high_or_low_interval_ != nullptr); |
| 760 | } |
| 761 | |
| 762 | void SetLowInterval(LiveInterval* low) { |
| 763 | DCHECK(IsHighInterval()); |
| 764 | high_or_low_interval_ = low; |
| 765 | } |
| 766 | |
| 767 | void SetHighInterval(LiveInterval* high) { |
| 768 | DCHECK(IsLowInterval()); |
| 769 | high_or_low_interval_ = high; |
| 770 | } |
| 771 | |
| 772 | void AddHighInterval(bool is_temp = false) { |
Nicolas Geoffray | 1ba1981 | 2015-04-21 09:12:40 +0100 | [diff] [blame] | 773 | DCHECK(IsParent()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 774 | DCHECK(!HasHighInterval()); |
| 775 | DCHECK(!HasLowInterval()); |
| 776 | high_or_low_interval_ = new (allocator_) LiveInterval( |
| 777 | allocator_, type_, defined_by_, false, kNoRegister, is_temp, false, true); |
| 778 | high_or_low_interval_->high_or_low_interval_ = this; |
| 779 | if (first_range_ != nullptr) { |
| 780 | high_or_low_interval_->first_range_ = first_range_->Dup(allocator_); |
David Brazdil | c08675c | 2015-04-17 15:49:51 +0100 | [diff] [blame] | 781 | high_or_low_interval_->last_range_ = high_or_low_interval_->first_range_->GetLastRange(); |
David Brazdil | 3fc992f | 2015-04-16 18:31:55 +0100 | [diff] [blame] | 782 | high_or_low_interval_->range_search_start_ = high_or_low_interval_->first_range_; |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 783 | } |
| 784 | if (first_use_ != nullptr) { |
| 785 | high_or_low_interval_->first_use_ = first_use_->Dup(allocator_); |
| 786 | } |
Nicolas Geoffray | 4ed947a | 2015-04-27 16:58:06 +0100 | [diff] [blame] | 787 | |
| 788 | if (first_env_use_ != nullptr) { |
| 789 | high_or_low_interval_->first_env_use_ = first_env_use_->Dup(allocator_); |
| 790 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 791 | } |
| 792 | |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 793 | // Returns whether an interval, when it is non-split, is using |
| 794 | // the same register of one of its input. |
| 795 | bool IsUsingInputRegister() const { |
David Brazdil | 3fc992f | 2015-04-16 18:31:55 +0100 | [diff] [blame] | 796 | CHECK(kIsDebugBuild) << "Function should be used only for DCHECKs"; |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 797 | if (defined_by_ != nullptr && !IsSplit()) { |
| 798 | for (HInputIterator it(defined_by_); !it.Done(); it.Advance()) { |
| 799 | LiveInterval* interval = it.Current()->GetLiveInterval(); |
| 800 | |
David Brazdil | 3fc992f | 2015-04-16 18:31:55 +0100 | [diff] [blame] | 801 | // Find the interval that covers `defined_by`_. Calls to this function |
| 802 | // are made outside the linear scan, hence we need to use CoversSlow. |
| 803 | while (interval != nullptr && !interval->CoversSlow(defined_by_->GetLifetimePosition())) { |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 804 | interval = interval->GetNextSibling(); |
| 805 | } |
| 806 | |
| 807 | // Check if both intervals have the same register of the same kind. |
| 808 | if (interval != nullptr |
| 809 | && interval->SameRegisterKind(*this) |
| 810 | && interval->GetRegister() == GetRegister()) { |
| 811 | return true; |
| 812 | } |
| 813 | } |
| 814 | } |
| 815 | return false; |
| 816 | } |
| 817 | |
| 818 | // Returns whether an interval, when it is non-split, can safely use |
| 819 | // the same register of one of its input. Note that this method requires |
| 820 | // IsUsingInputRegister() to be true. |
| 821 | bool CanUseInputRegister() const { |
David Brazdil | 3fc992f | 2015-04-16 18:31:55 +0100 | [diff] [blame] | 822 | CHECK(kIsDebugBuild) << "Function should be used only for DCHECKs"; |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 823 | DCHECK(IsUsingInputRegister()); |
| 824 | if (defined_by_ != nullptr && !IsSplit()) { |
| 825 | LocationSummary* locations = defined_by_->GetLocations(); |
| 826 | if (locations->OutputCanOverlapWithInputs()) { |
| 827 | return false; |
| 828 | } |
| 829 | for (HInputIterator it(defined_by_); !it.Done(); it.Advance()) { |
| 830 | LiveInterval* interval = it.Current()->GetLiveInterval(); |
| 831 | |
David Brazdil | 3fc992f | 2015-04-16 18:31:55 +0100 | [diff] [blame] | 832 | // Find the interval that covers `defined_by`_. Calls to this function |
| 833 | // are made outside the linear scan, hence we need to use CoversSlow. |
| 834 | while (interval != nullptr && !interval->CoversSlow(defined_by_->GetLifetimePosition())) { |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 835 | interval = interval->GetNextSibling(); |
| 836 | } |
| 837 | |
| 838 | if (interval != nullptr |
| 839 | && interval->SameRegisterKind(*this) |
| 840 | && interval->GetRegister() == GetRegister()) { |
| 841 | // We found the input that has the same register. Check if it is live after |
| 842 | // `defined_by`_. |
David Brazdil | 3fc992f | 2015-04-16 18:31:55 +0100 | [diff] [blame] | 843 | return !interval->CoversSlow(defined_by_->GetLifetimePosition() + 1); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 844 | } |
| 845 | } |
| 846 | } |
| 847 | LOG(FATAL) << "Unreachable"; |
| 848 | UNREACHABLE(); |
| 849 | } |
| 850 | |
Nicolas Geoffray | 5588e58 | 2015-04-14 14:10:59 +0100 | [diff] [blame] | 851 | void AddSafepoint(HInstruction* instruction) { |
| 852 | SafepointPosition* safepoint = new (allocator_) SafepointPosition(instruction); |
| 853 | if (first_safepoint_ == nullptr) { |
| 854 | first_safepoint_ = last_safepoint_ = safepoint; |
| 855 | } else { |
| 856 | DCHECK_LT(last_safepoint_->GetPosition(), safepoint->GetPosition()); |
| 857 | last_safepoint_->SetNext(safepoint); |
| 858 | last_safepoint_ = safepoint; |
| 859 | } |
| 860 | } |
| 861 | |
| 862 | SafepointPosition* GetFirstSafepoint() const { |
Nicolas Geoffray | 5588e58 | 2015-04-14 14:10:59 +0100 | [diff] [blame] | 863 | return first_safepoint_; |
| 864 | } |
| 865 | |
David Brazdil | 3fc992f | 2015-04-16 18:31:55 +0100 | [diff] [blame] | 866 | // Resets the starting point for range-searching queries to the first range. |
| 867 | // Intervals must be reset prior to starting a new linear scan over them. |
| 868 | void ResetSearchCache() { |
| 869 | range_search_start_ = first_range_; |
| 870 | } |
| 871 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 872 | private: |
Mingyao Yang | 296bd60 | 2014-10-06 16:47:28 -0700 | [diff] [blame] | 873 | LiveInterval(ArenaAllocator* allocator, |
| 874 | Primitive::Type type, |
| 875 | HInstruction* defined_by = nullptr, |
| 876 | bool is_fixed = false, |
| 877 | int reg = kNoRegister, |
| 878 | bool is_temp = false, |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 879 | bool is_slow_path_safepoint = false, |
| 880 | bool is_high_interval = false) |
Mingyao Yang | 296bd60 | 2014-10-06 16:47:28 -0700 | [diff] [blame] | 881 | : allocator_(allocator), |
| 882 | first_range_(nullptr), |
| 883 | last_range_(nullptr), |
David Brazdil | 3fc992f | 2015-04-16 18:31:55 +0100 | [diff] [blame] | 884 | range_search_start_(nullptr), |
Nicolas Geoffray | 5588e58 | 2015-04-14 14:10:59 +0100 | [diff] [blame] | 885 | first_safepoint_(nullptr), |
| 886 | last_safepoint_(nullptr), |
Mingyao Yang | 296bd60 | 2014-10-06 16:47:28 -0700 | [diff] [blame] | 887 | first_use_(nullptr), |
Nicolas Geoffray | 4ed947a | 2015-04-27 16:58:06 +0100 | [diff] [blame] | 888 | first_env_use_(nullptr), |
Mingyao Yang | 296bd60 | 2014-10-06 16:47:28 -0700 | [diff] [blame] | 889 | type_(type), |
| 890 | next_sibling_(nullptr), |
| 891 | parent_(this), |
| 892 | register_(reg), |
| 893 | spill_slot_(kNoSpillSlot), |
| 894 | is_fixed_(is_fixed), |
| 895 | is_temp_(is_temp), |
| 896 | is_slow_path_safepoint_(is_slow_path_safepoint), |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 897 | is_high_interval_(is_high_interval), |
| 898 | high_or_low_interval_(nullptr), |
Mingyao Yang | 296bd60 | 2014-10-06 16:47:28 -0700 | [diff] [blame] | 899 | defined_by_(defined_by) {} |
| 900 | |
David Brazdil | 3fc992f | 2015-04-16 18:31:55 +0100 | [diff] [blame] | 901 | // Searches for a LiveRange that either covers the given position or is the |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 902 | // first next LiveRange. Returns null if no such LiveRange exists. Ranges |
David Brazdil | 3fc992f | 2015-04-16 18:31:55 +0100 | [diff] [blame] | 903 | // known to end before `position` can be skipped with `search_start`. |
| 904 | LiveRange* FindRangeAtOrAfter(size_t position, LiveRange* search_start) const { |
David Brazdil | 5b8e6a5 | 2015-02-25 16:17:05 +0000 | [diff] [blame] | 905 | if (kIsDebugBuild) { |
David Brazdil | 3fc992f | 2015-04-16 18:31:55 +0100 | [diff] [blame] | 906 | if (search_start != first_range_) { |
| 907 | // If we are not searching the entire list of ranges, make sure we do |
| 908 | // not skip the range we are searching for. |
| 909 | if (search_start == nullptr) { |
| 910 | DCHECK(IsDeadAt(position)); |
| 911 | } else if (search_start->GetStart() > position) { |
| 912 | DCHECK_EQ(search_start, FindRangeAtOrAfter(position, first_range_)); |
| 913 | } |
David Brazdil | 5b8e6a5 | 2015-02-25 16:17:05 +0000 | [diff] [blame] | 914 | } |
| 915 | } |
| 916 | |
David Brazdil | 3fc992f | 2015-04-16 18:31:55 +0100 | [diff] [blame] | 917 | LiveRange* range; |
| 918 | for (range = search_start; |
| 919 | range != nullptr && range->GetEnd() <= position; |
| 920 | range = range->GetNext()) { |
| 921 | continue; |
David Brazdil | 5b8e6a5 | 2015-02-25 16:17:05 +0000 | [diff] [blame] | 922 | } |
David Brazdil | 3fc992f | 2015-04-16 18:31:55 +0100 | [diff] [blame] | 923 | return range; |
David Brazdil | 5b8e6a5 | 2015-02-25 16:17:05 +0000 | [diff] [blame] | 924 | } |
| 925 | |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 926 | bool DefinitionRequiresRegister() const { |
| 927 | DCHECK(IsParent()); |
| 928 | LocationSummary* locations = defined_by_->GetLocations(); |
| 929 | Location location = locations->Out(); |
| 930 | // This interval is the first interval of the instruction. If the output |
| 931 | // of the instruction requires a register, we return the position of that instruction |
| 932 | // as the first register use. |
| 933 | if (location.IsUnallocated()) { |
| 934 | if ((location.GetPolicy() == Location::kRequiresRegister) |
| 935 | || (location.GetPolicy() == Location::kSameAsFirstInput |
| 936 | && (locations->InAt(0).IsRegister() |
| 937 | || locations->InAt(0).IsRegisterPair() |
| 938 | || locations->InAt(0).GetPolicy() == Location::kRequiresRegister))) { |
| 939 | return true; |
| 940 | } else if ((location.GetPolicy() == Location::kRequiresFpuRegister) |
| 941 | || (location.GetPolicy() == Location::kSameAsFirstInput |
| 942 | && (locations->InAt(0).IsFpuRegister() |
| 943 | || locations->InAt(0).IsFpuRegisterPair() |
| 944 | || locations->InAt(0).GetPolicy() == Location::kRequiresFpuRegister))) { |
| 945 | return true; |
| 946 | } |
| 947 | } else if (location.IsRegister() || location.IsRegisterPair()) { |
| 948 | return true; |
| 949 | } |
| 950 | return false; |
| 951 | } |
| 952 | |
| 953 | bool IsDefiningPosition(size_t position) const { |
| 954 | return IsParent() && (position == GetStart()); |
| 955 | } |
| 956 | |
| 957 | bool HasSynthesizeUseAt(size_t position) const { |
| 958 | UsePosition* use = first_use_; |
| 959 | while (use != nullptr) { |
| 960 | size_t use_position = use->GetPosition(); |
| 961 | if ((use_position == position) && use->IsSynthesized()) { |
| 962 | return true; |
| 963 | } |
| 964 | if (use_position > position) break; |
| 965 | use = use->GetNext(); |
| 966 | } |
| 967 | return false; |
| 968 | } |
| 969 | |
| 970 | void AddBackEdgeUses(const HBasicBlock& block_at_use) { |
| 971 | DCHECK(block_at_use.IsInLoop()); |
| 972 | // Add synthesized uses at the back edge of loops to help the register allocator. |
| 973 | // Note that this method is called in decreasing liveness order, to faciliate adding |
| 974 | // uses at the head of the `first_use_` linked list. Because below |
| 975 | // we iterate from inner-most to outer-most, which is in increasing liveness order, |
| 976 | // we need to take extra care of how the `first_use_` linked list is being updated. |
| 977 | UsePosition* first_in_new_list = nullptr; |
| 978 | UsePosition* last_in_new_list = nullptr; |
| 979 | for (HLoopInformationOutwardIterator it(block_at_use); |
| 980 | !it.Done(); |
| 981 | it.Advance()) { |
| 982 | HLoopInformation* current = it.Current(); |
| 983 | if (GetDefinedBy()->GetLifetimePosition() >= current->GetHeader()->GetLifetimeStart()) { |
| 984 | // This interval is defined in the loop. We can stop going outward. |
| 985 | break; |
| 986 | } |
| 987 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 988 | // We're only adding a synthesized use at the last back edge. Adding syntehsized uses on |
| 989 | // all back edges is not necessary: anything used in the loop will have its use at the |
| 990 | // last back edge. If we want branches in a loop to have better register allocation than |
| 991 | // another branch, then it is the linear order we should change. |
| 992 | size_t back_edge_use_position = current->GetLifetimeEnd(); |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 993 | if ((first_use_ != nullptr) && (first_use_->GetPosition() <= back_edge_use_position)) { |
| 994 | // There was a use already seen in this loop. Therefore the previous call to `AddUse` |
| 995 | // already inserted the backedge use. We can stop going outward. |
| 996 | DCHECK(HasSynthesizeUseAt(back_edge_use_position)); |
| 997 | break; |
| 998 | } |
| 999 | |
| 1000 | DCHECK(last_in_new_list == nullptr |
| 1001 | || back_edge_use_position > last_in_new_list->GetPosition()); |
| 1002 | |
| 1003 | UsePosition* new_use = new (allocator_) UsePosition( |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1004 | /* user */ nullptr, |
| 1005 | /* environment */ nullptr, |
| 1006 | UsePosition::kNoInput, |
| 1007 | back_edge_use_position, |
| 1008 | /* next */ nullptr); |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 1009 | |
| 1010 | if (last_in_new_list != nullptr) { |
| 1011 | // Going outward. The latest created use needs to point to the new use. |
| 1012 | last_in_new_list->SetNext(new_use); |
| 1013 | } else { |
| 1014 | // This is the inner-most loop. |
| 1015 | DCHECK_EQ(current, block_at_use.GetLoopInformation()); |
| 1016 | first_in_new_list = new_use; |
| 1017 | } |
| 1018 | last_in_new_list = new_use; |
| 1019 | } |
| 1020 | // Link the newly created linked list with `first_use_`. |
| 1021 | if (last_in_new_list != nullptr) { |
| 1022 | last_in_new_list->SetNext(first_use_); |
| 1023 | first_use_ = first_in_new_list; |
| 1024 | } |
| 1025 | } |
| 1026 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1027 | ArenaAllocator* const allocator_; |
| 1028 | |
| 1029 | // Ranges of this interval. We need a quick access to the last range to test |
| 1030 | // for liveness (see `IsDeadAt`). |
| 1031 | LiveRange* first_range_; |
| 1032 | LiveRange* last_range_; |
| 1033 | |
David Brazdil | 3fc992f | 2015-04-16 18:31:55 +0100 | [diff] [blame] | 1034 | // The first range at or after the current position of a linear scan. It is |
| 1035 | // used to optimize range-searching queries. |
| 1036 | LiveRange* range_search_start_; |
| 1037 | |
Nicolas Geoffray | 43af728 | 2015-04-16 13:01:01 +0100 | [diff] [blame] | 1038 | // Safepoints where this interval is live. |
Nicolas Geoffray | 5588e58 | 2015-04-14 14:10:59 +0100 | [diff] [blame] | 1039 | SafepointPosition* first_safepoint_; |
| 1040 | SafepointPosition* last_safepoint_; |
| 1041 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1042 | // Uses of this interval. Note that this linked list is shared amongst siblings. |
| 1043 | UsePosition* first_use_; |
Nicolas Geoffray | 4ed947a | 2015-04-27 16:58:06 +0100 | [diff] [blame] | 1044 | UsePosition* first_env_use_; |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1045 | |
| 1046 | // The instruction type this interval corresponds to. |
| 1047 | const Primitive::Type type_; |
| 1048 | |
| 1049 | // Live interval that is the result of a split. |
| 1050 | LiveInterval* next_sibling_; |
| 1051 | |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 1052 | // The first interval from which split intervals come from. |
| 1053 | LiveInterval* parent_; |
| 1054 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1055 | // The register allocated to this interval. |
| 1056 | int register_; |
| 1057 | |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 1058 | // The spill slot allocated to this interval. |
| 1059 | int spill_slot_; |
| 1060 | |
| 1061 | // Whether the interval is for a fixed register. |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1062 | const bool is_fixed_; |
| 1063 | |
| 1064 | // Whether the interval is for a temporary. |
| 1065 | const bool is_temp_; |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 1066 | |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 1067 | // Whether the interval is for a safepoint that calls on slow path. |
| 1068 | const bool is_slow_path_safepoint_; |
| 1069 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 1070 | // Whether this interval is a synthesized interval for register pair. |
| 1071 | const bool is_high_interval_; |
| 1072 | |
| 1073 | // If this interval needs a register pair, the high or low equivalent. |
| 1074 | // `is_high_interval_` tells whether this holds the low or the high. |
| 1075 | LiveInterval* high_or_low_interval_; |
| 1076 | |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 1077 | // The instruction represented by this interval. |
| 1078 | HInstruction* const defined_by_; |
| 1079 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1080 | static constexpr int kNoRegister = -1; |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 1081 | static constexpr int kNoSpillSlot = -1; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1082 | |
Nicolas Geoffray | dd8f887 | 2015-01-15 15:37:37 +0000 | [diff] [blame] | 1083 | ART_FRIEND_TEST(RegisterAllocatorTest, SpillInactive); |
| 1084 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1085 | DISALLOW_COPY_AND_ASSIGN(LiveInterval); |
| 1086 | }; |
| 1087 | |
Nicolas Geoffray | 915b9d0 | 2015-03-11 15:11:19 +0000 | [diff] [blame] | 1088 | /** |
| 1089 | * Analysis that computes the liveness of instructions: |
| 1090 | * |
| 1091 | * (a) Non-environment uses of an instruction always make |
| 1092 | * the instruction live. |
| 1093 | * (b) Environment uses of an instruction whose type is |
| 1094 | * object (that is, non-primitive), make the instruction live. |
| 1095 | * This is due to having to keep alive objects that have |
| 1096 | * finalizers deleting native objects. |
| 1097 | * (c) When the graph has the debuggable property, environment uses |
| 1098 | * of an instruction that has a primitive type make the instruction live. |
| 1099 | * If the graph does not have the debuggable property, the environment |
| 1100 | * use has no effect, and may get a 'none' value after register allocation. |
| 1101 | * |
| 1102 | * (b) and (c) are implemented through SsaLivenessAnalysis::ShouldBeLiveForEnvironment. |
| 1103 | */ |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1104 | class SsaLivenessAnalysis : public ValueObject { |
| 1105 | public: |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 1106 | SsaLivenessAnalysis(HGraph* graph, CodeGenerator* codegen) |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1107 | : graph_(graph), |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 1108 | codegen_(codegen), |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 1109 | block_infos_(graph->GetBlocks().size(), |
| 1110 | nullptr, |
| 1111 | graph->GetArena()->Adapter(kArenaAllocSsaLiveness)), |
| 1112 | instructions_from_ssa_index_(graph->GetArena()->Adapter(kArenaAllocSsaLiveness)), |
| 1113 | instructions_from_lifetime_position_(graph->GetArena()->Adapter(kArenaAllocSsaLiveness)), |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1114 | number_of_ssa_values_(0) { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1115 | } |
| 1116 | |
| 1117 | void Analyze(); |
| 1118 | |
| 1119 | BitVector* GetLiveInSet(const HBasicBlock& block) const { |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 1120 | return &block_infos_[block.GetBlockId()]->live_in_; |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1121 | } |
| 1122 | |
| 1123 | BitVector* GetLiveOutSet(const HBasicBlock& block) const { |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 1124 | return &block_infos_[block.GetBlockId()]->live_out_; |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1125 | } |
| 1126 | |
| 1127 | BitVector* GetKillSet(const HBasicBlock& block) const { |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 1128 | return &block_infos_[block.GetBlockId()]->kill_; |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1129 | } |
| 1130 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1131 | HInstruction* GetInstructionFromSsaIndex(size_t index) const { |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 1132 | return instructions_from_ssa_index_[index]; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1133 | } |
| 1134 | |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 1135 | HInstruction* GetInstructionFromPosition(size_t index) const { |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 1136 | return instructions_from_lifetime_position_[index]; |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 1137 | } |
| 1138 | |
Nicolas Geoffray | 8cbab3c | 2015-04-23 15:14:36 +0100 | [diff] [blame] | 1139 | HBasicBlock* GetBlockFromPosition(size_t index) const { |
Nicolas Geoffray | fbda5f3 | 2015-04-29 14:16:00 +0100 | [diff] [blame] | 1140 | HInstruction* instruction = GetInstructionFromPosition(index); |
Nicolas Geoffray | 8cbab3c | 2015-04-23 15:14:36 +0100 | [diff] [blame] | 1141 | if (instruction == nullptr) { |
| 1142 | // If we are at a block boundary, get the block following. |
Nicolas Geoffray | fbda5f3 | 2015-04-29 14:16:00 +0100 | [diff] [blame] | 1143 | instruction = GetInstructionFromPosition(index + 1); |
Nicolas Geoffray | 8cbab3c | 2015-04-23 15:14:36 +0100 | [diff] [blame] | 1144 | } |
| 1145 | return instruction->GetBlock(); |
| 1146 | } |
| 1147 | |
Nicolas Geoffray | fbda5f3 | 2015-04-29 14:16:00 +0100 | [diff] [blame] | 1148 | bool IsAtBlockBoundary(size_t index) const { |
| 1149 | return GetInstructionFromPosition(index) == nullptr; |
| 1150 | } |
| 1151 | |
Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 1152 | HInstruction* GetTempUser(LiveInterval* temp) const { |
| 1153 | // A temporary shares the same lifetime start as the instruction that requires it. |
| 1154 | DCHECK(temp->IsTemp()); |
Nicolas Geoffray | f01d344 | 2015-03-27 17:15:49 +0000 | [diff] [blame] | 1155 | HInstruction* user = GetInstructionFromPosition(temp->GetStart() / 2); |
| 1156 | DCHECK_EQ(user, temp->GetFirstUse()->GetUser()); |
| 1157 | return user; |
| 1158 | } |
| 1159 | |
| 1160 | size_t GetTempIndex(LiveInterval* temp) const { |
| 1161 | // We use the input index to store the index of the temporary in the user's temporary list. |
| 1162 | DCHECK(temp->IsTemp()); |
| 1163 | return temp->GetFirstUse()->GetInputIndex(); |
Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 1164 | } |
| 1165 | |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 1166 | size_t GetMaxLifetimePosition() const { |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 1167 | return instructions_from_lifetime_position_.size() * 2 - 1; |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 1168 | } |
| 1169 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1170 | size_t GetNumberOfSsaValues() const { |
| 1171 | return number_of_ssa_values_; |
| 1172 | } |
| 1173 | |
Andreas Gampe | 7c3952f | 2015-02-19 18:21:24 -0800 | [diff] [blame] | 1174 | static constexpr const char* kLivenessPassName = "liveness"; |
| 1175 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1176 | private: |
Nicolas Geoffray | 0d3f578 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 1177 | // Linearize the graph so that: |
| 1178 | // (1): a block is always after its dominator, |
| 1179 | // (2): blocks of loops are contiguous. |
| 1180 | // This creates a natural and efficient ordering when visualizing live ranges. |
| 1181 | void LinearizeGraph(); |
| 1182 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1183 | // Give an SSA number to each instruction that defines a value used by another instruction, |
| 1184 | // and setup the lifetime information of each instruction and block. |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1185 | void NumberInstructions(); |
| 1186 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1187 | // Compute live ranges of instructions, as well as live_in, live_out and kill sets. |
| 1188 | void ComputeLiveness(); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1189 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1190 | // Compute the live ranges of instructions, as well as the initial live_in, live_out and |
| 1191 | // kill sets, that do not take into account backward branches. |
| 1192 | void ComputeLiveRanges(); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1193 | |
| 1194 | // After computing the initial sets, this method does a fixed point |
| 1195 | // calculation over the live_in and live_out set to take into account |
| 1196 | // backwards branches. |
| 1197 | void ComputeLiveInAndLiveOutSets(); |
| 1198 | |
| 1199 | // Update the live_in set of the block and returns whether it has changed. |
| 1200 | bool UpdateLiveIn(const HBasicBlock& block); |
| 1201 | |
| 1202 | // Update the live_out set of the block and returns whether it has changed. |
| 1203 | bool UpdateLiveOut(const HBasicBlock& block); |
| 1204 | |
Mingyao Yang | 718493c | 2015-07-22 15:56:34 -0700 | [diff] [blame] | 1205 | // Returns whether `instruction` in an HEnvironment held by `env_holder` |
| 1206 | // should be kept live by the HEnvironment. |
| 1207 | static bool ShouldBeLiveForEnvironment(HInstruction* env_holder, |
| 1208 | HInstruction* instruction) { |
Nicolas Geoffray | 915b9d0 | 2015-03-11 15:11:19 +0000 | [diff] [blame] | 1209 | if (instruction == nullptr) return false; |
Mingyao Yang | 718493c | 2015-07-22 15:56:34 -0700 | [diff] [blame] | 1210 | // A value that's not live in compiled code may still be needed in interpreter, |
| 1211 | // due to code motion, etc. |
| 1212 | if (env_holder->IsDeoptimize()) return true; |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 1213 | // A value live at a throwing instruction in a try block may be copied by |
| 1214 | // the exception handler to its location at the top of the catch block. |
| 1215 | if (env_holder->CanThrowIntoCatchBlock()) return true; |
Nicolas Geoffray | 915b9d0 | 2015-03-11 15:11:19 +0000 | [diff] [blame] | 1216 | if (instruction->GetBlock()->GetGraph()->IsDebuggable()) return true; |
| 1217 | return instruction->GetType() == Primitive::kPrimNot; |
| 1218 | } |
| 1219 | |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 1220 | HGraph* const graph_; |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 1221 | CodeGenerator* const codegen_; |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 1222 | ArenaVector<BlockInfo*> block_infos_; |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 1223 | |
| 1224 | // Temporary array used when computing live_in, live_out, and kill sets. |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 1225 | ArenaVector<HInstruction*> instructions_from_ssa_index_; |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 1226 | |
| 1227 | // Temporary array used when inserting moves in the graph. |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 1228 | ArenaVector<HInstruction*> instructions_from_lifetime_position_; |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1229 | size_t number_of_ssa_values_; |
| 1230 | |
Nicolas Geoffray | 8cbab3c | 2015-04-23 15:14:36 +0100 | [diff] [blame] | 1231 | ART_FRIEND_TEST(RegisterAllocatorTest, SpillInactive); |
Nicolas Geoffray | 23a8188 | 2015-06-01 18:12:38 +0100 | [diff] [blame] | 1232 | ART_FRIEND_TEST(RegisterAllocatorTest, FreeUntil); |
Nicolas Geoffray | 8cbab3c | 2015-04-23 15:14:36 +0100 | [diff] [blame] | 1233 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1234 | DISALLOW_COPY_AND_ASSIGN(SsaLivenessAnalysis); |
| 1235 | }; |
| 1236 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1237 | } // namespace art |
| 1238 | |
| 1239 | #endif // ART_COMPILER_OPTIMIZING_SSA_LIVENESS_ANALYSIS_H_ |